slj90 Posted November 15, 2010 Share Posted November 15, 2010 I am trying to write to a mysql database but I am getting an error. Here is the code: <?php $Username = $_POST['Username']; $Password = $_POST ['Password']; $Email = $_POST ['Email']; $Goal = $_Goal ['Goal']; $dbhost="mysql4.000webhost.com"; $username="a7564065_si"; $password="*****"; $database="a7564065_food"; mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="INSERT INTO Users (id, Username, Password, Email, Goal) mysql_query($query) or die ('Error creating account') echo "Account created: " .$Username. " .$Goal ; ?> Error mesage is: Parse error: syntax error, unexpected T_STRING in /home/a7564065/public_html/add.php on line 21 Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/ Share on other sites More sharing options...
TrueColors Posted November 15, 2010 Share Posted November 15, 2010 $query="INSERT INTO Users (id, Username, Password, Email, Goal) mysql_query($query) or die ('Error creating account') is missing a "; on the first line, and ; on the second. It should be like this $query="INSERT INTO Users (id, Username, Password, Email, Goal)"; mysql_query($query) or die ('Error creating account'); Also, is $_GOAL a valid variable, Shouldn't it $_POST? Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134247 Share on other sites More sharing options...
slj90 Posted November 15, 2010 Author Share Posted November 15, 2010 Thanks for those errors. However it now says 'Error making account' when I run the script.. <?php $Username = $_POST['Username']; $Password = $_POST['Password']; $Email = $_POST['Email']; $Goal = $_POST['Goal']; $dbhost="mysql4.000webhost.com"; $username="a7564065_si"; $password="simple989"; $database="a7564065_food"; mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="INSERT INTO Users (id, Username, Password, Email, Goal)"; mysql_query($query) or die ('Error creating account'); ?> Here is the page with the form on.. <HTML> <HEAD> <TITLE>Form Handling with PHP</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> <FORM METHOD=POST ACTION="add.php"> <input type="hidden" name="id" value="NULL"> <TABLE> <TR height="20"> <TD colspan="2"><FONT SIZE="+0" face="verdana"> Register</TD> </TR> <TR height="50"> <td></td> </TR> <TR> <TD align="left"><FONT SIZE="+0" face="verdana"><b>Username <br> Password<br> Email<br> Goal</b></td> <td><INPUT TYPE="text" NAME="Username"> <br> <INPUT TYPE="text" NAME="Password"> <br> <INPUT TYPE="text" NAME="Email"><br> <select name="Goal"> <option value="WeightLoss">Weight Loss</option> <option value="GainMuscle">Gain Muscle</option> <option value="Fitness">Fitness</option> </select></TD> </TR> <tr> <td colspan="2"><center> <INPUT TYPE="submit" value="Submit"> </td> </tr> </TABLE> </FORM> </BODY> </HTML> Thanks Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134259 Share on other sites More sharing options...
BlueSkyIS Posted November 15, 2010 Share Posted November 15, 2010 seeing the error is better than just knowing there is one. mysql_query($query) or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134260 Share on other sites More sharing options...
slj90 Posted November 15, 2010 Author Share Posted November 15, 2010 Good idea, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Thank you Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134261 Share on other sites More sharing options...
TrueColors Posted November 15, 2010 Share Posted November 15, 2010 I do not see what you are trying to insert. Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134262 Share on other sites More sharing options...
slj90 Posted November 15, 2010 Author Share Posted November 15, 2010 I do not see what you are trying to insert. The infomation the user inserts into the form Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134265 Share on other sites More sharing options...
TrueColors Posted November 15, 2010 Share Posted November 15, 2010 $query="INSERT INTO Users (id, Username, Password, Email, Goal)"; - this is inserting nothing. Where is the variables holding values to insert? INSERT INTO table (column) VALUES ('value') Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134270 Share on other sites More sharing options...
chintansshah Posted November 15, 2010 Share Posted November 15, 2010 Hey, I can't see any values in your insert query, you just create quesry with column name not with values. To see Insert query syntax, use below link http://dev.mysql.com/doc/refman/5.0/en/insert.html Link to comment https://forums.phpfreaks.com/topic/218686-syntax-error-help/#findComment-1134295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.