If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > form doesnt save in mysql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-09, 03:55
don_log don_log is offline
Registered User
 
Join Date: Jun 2008
Location: pakistan
Posts: 109
form doesnt save in mysql

i have a problem with phpmysql i want to save form data in mysql
i created a form and coding just like this
PHP Code:
<?
$name
=$_post['name'];
$email=$_post['email'];
$subject=$_post['subject'];
$comment=$_post['comment'];
$host="localhost";//mysql host
$user="root";//mysql user
$pass="";//mysql password
$con=mysql_connect($host,$user,$pass);
$select=mysql_select_db(a,$con);
$sql="insert into alrehman(name,email,subject,comment)Values('$name','$email','$subject','$comments');";
$query=mysql_query($sql);
mysql_close();
?>

but it doesn't save just empty box shown in mysql database it created row but emptied why this happen
Reply With Quote
  #2 (permalink)  
Old 10-17-09, 05:04
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
have you checked there are values in the variables '$name','$email','$subject','$comments'
depending on how your PHP instgallation is configured you may need to prefix the values with $POST_ or $GET_
whilst you are at it you need to validate the data you write to the db.. accepting user input without validation OR converting to HTMLENTITIES you are leaving yourself open to attack from people wanting to subvert your site
PHP is a capitalisation aware environment $MAIL is not the same as $Mail

I'd sugegst you always examine the $MySQL_ErrNO function after each call to the DB
I'd suggest you learn some debugging skills, not least the judicious use of the die statement

eg
die (echo $sql);
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 10-20-09, 04:09
don_log don_log is offline
Registered User
 
Join Date: Jun 2008
Location: pakistan
Posts: 109
i agree with you healdem can you please suggest me the ready made contact form which will i place on my site and save form data in mysql is there any ready made form just i have to install that .
Reply With Quote
  #4 (permalink)  
Old 10-20-09, 04:12
don_log don_log is offline
Registered User
 
Join Date: Jun 2008
Location: pakistan
Posts: 109
you said

I'd sugegst you always examine the $MySQL_ErrNO function after each call to the DB
I'd suggest you learn some debugging skills, not least the judicious use of the die statement


tell me where can i learn this skill as well as making of content management system
Reply With Quote
  #5 (permalink)  
Old 10-20-09, 06:00
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
<?
$name=$_post['name'];
$email=$_post['email'];
$subject=$_post['subject'];
$comment=$_post['comment'];
$out .="name= $name, POST =".$_post['name']."\n";
$out .="email= $email, POST =".$_post['email']."\n";
$out ."subject= $subject, POST =".$_post['subject']."\n;
$out .="comment= $comment=, POST =".$_post['comment']."\n
die (echo $out);


debugging is the art of carefully examining what your program is doing against what you expect it to be doing. so check what inputs you are getting
test the program with known good data

so in thsi case
you knwo you are getting something written to the db, its blank lines, but the sql is doing something

so you need to develop a strategy to work out what is going wrong with your program. work through a block of code and make certain that what you expect to happen is happening.
check inputs
check outputs
analyse the evidence and come to a conclusion as to where the fault lies, or where you think it lies. you are seeking to find the fault, so finding areas which are working is just as useful as finding areas which aren't working.

as you cross off each bit of code that is working you come closer to where the fault is. sometimes thats the real black art in debugging, making a good guess where the fault lies.

the other option here is to echo the sql you are suign to the screen and make certain that what you are sending to the sql engine is what you think. it also pays to examine the response from the sql engine before doing any further processing. in php you need to examine the mysql_errno and/or mysql_error functions to see if the sql engine complained about what it was sent.

unlike many other languages php is very (many would argue too) fault tolerant

make certain that whilst in development you set the error reporting level appropriately
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #6 (permalink)  
Old 10-22-09, 01:28
don_log don_log is offline
Registered User
 
Join Date: Jun 2008
Location: pakistan
Posts: 109
explanation please

can you please explain the coding that you write about just explain 1st line

$out .="name= $name, POST =".$_post['name'].

what's mean of . after $out
and another is name=$name
i couldn't understand what the mean cause i am new in such things new thing you tellme and i couldn't understand
Reply With Quote
  #7 (permalink)  
Old 10-22-09, 03:52
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
thats a building a variable to display the values of your varaibles
its the equivalent of

$out .="name=".$name; //add the $name to the displa\y variable $out
$out .=" POST =".$_post['name'] //add the value from the $POST_ global variable 'name'
$out .="\n"; //add a form feed to $out

//repeat for the other 3 variables

die (echo $out); //then stop execution of the script and display the value of $out on the screen

whilst you are at it make certain that you switch on full error reporting
error_reporting(E_All & E_STRICT)

I can't remmebr if its | or & to doo a bitwise add.. check da manuel (PHP: Hypertext Preprocessor) for details
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #8 (permalink)  
Old 10-22-09, 04:44
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
or you could just print out all the POST values at once with :
Code:
print_r( $_POST );
Reply With Quote
  #9 (permalink)  
Old 10-22-09, 05:04
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
true
but I'm hoping to convince DON_LOG to develop some debugging skills, or at least the vesitge of analysing a problem and try to develop a strategy to devise a solution or a methodology to get a solution

after all there is a world of difference between $_post and $_POST
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On