smilie Posted December 26, 2003 Share Posted December 26, 2003 I\'m new to PHP/MySQl and i\'m trying to enter data into a db. It keeps giving me error\'s saying the form vaules are not defined. Here is the PHP file: <?php $host = "localhost"; $username ="root"; $password ="TheDBPassword"; $database ="mydb"; mysql_connect($host,$username,$password) or die( "<br><center>Unable to connect to database server</center>"); @mysql_select_db($database) or die("<br><center>Unable to select to database</center>"); // Line 13 is the line below $query = "INSERT INTO employees VALUES ("$first","$last","$address","$position")"; mysql_query($query); mysql_close() ?> Here is the Form File <html> <body> <form action="test14.php" method="post"> First: <input type="text" name="first"><p> Last: <input type="text" name="last"><p> Address: <input type="text" name="address"><p> Position: <input type="text" name="position"><p> <input type="submit"><p> </form> </body> </html> The Error Messages i get: (With quotes around value example: \"$first\") Parse error: parse error in /Library/WebServer/Documents/test14.php on line 13 or (Without quotes around value example: $first) Notice: Undefined variable: first in /Library/WebServer/Documents/test14.php on line 13 Notice: Undefined variable: last in /Library/WebServer/Documents/test14.php on line 13 Notice: Undefined variable: address in /Library/WebServer/Documents/test14.php on line 13 Notice: Undefined variable: position in /Library/WebServer/Documents/test14.php on line 13 Anything will help, Thanks K Quote Link to comment Share on other sites More sharing options...
WhiteDevil Posted December 26, 2003 Share Posted December 26, 2003 Unless register globals is switched on you will have to tell the processing form what the form variables were: $firstname = $HTTP_POST_VARS[\"firstnamefield\"]; $lastname = $HTTP_POST_VARS[\"lastnamefield\"]; On your form use \"method=post\". This should hopefully write each value to a variable which can then be added to the form... Any more problems, will try to help Quote Link to comment Share on other sites More sharing options...
DaMaAn Posted December 26, 2003 Share Posted December 26, 2003 $query = \\\"INSERT INTO employees VALUES (\\\"$first\\\",\\\"$last\\\",\\\"$address\\\",\\\"$position\\\")\\\"; Try to use \' around your insert statement OR escape all the rest of the \" used. Like this: $query = \'INSERT INTO employees VALUES ("\'.$first.\'","\'.$last.\'","\'.$address.\'","\'.$position.\'")\'; This will not translate any PHP variables so they must be concatenated into the string. or $query = "INSERT INTO employees VALUES (/"$first/",/"$last/",/"$address/",/"$position/")"; if you must have \" in the INSERT statement (doubt that) or $query = "INSERT INTO employees VALUES (\'$first\',\'$last\',\'$address\',\'$position\')"; Will probably produce the correct result with the \"nicest\" code. The problem is that you use the same quotes in the string as quoting the string. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.