ChompGator Posted August 6, 2008 Share Posted August 6, 2008 Parse error: parse error, unexpected T_STRING in d:\hosting\member\aiim\login\members\handle.php on line 13 I have revised my script to use mysql-update. I have a form that users can fill out to change their profile > upon submission the database table is supposed to update the changes...Im trying to ensure that it is only updating the 'company' based on the usersID number...that way if you had two john smiths in your database, that wont matter because the script is updating based on the users ID number. here is handle.php (the script that should update the fields in the databasE) <?php session_start(); $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name // Connect to DB $db = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($db_name); UPDATE aiimjoin SET company = WHERE uid = $_SESSION['uid']; //I know this is wrong, any advice? // Step 3 $result = mysql_query($sql) or die ( mysql_error() ); ?> Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/ Share on other sites More sharing options...
xstevey_bx Posted August 6, 2008 Share Posted August 6, 2008 $sql = "UPDATE aiimjoin SET company ='What you want company set to' WHERE uid ='$_SESSION[uid]'"; You said in your code $result = mysql_query($sql) or die ( mysql_error() ); The mysql_query($sql) part is looking for a $sql variable with a mysql query. You have set the query, but it is not assigned to a variable. Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609699 Share on other sites More sharing options...
ChompGator Posted August 6, 2008 Author Share Posted August 6, 2008 Nope, still didn't work, same error Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609705 Share on other sites More sharing options...
elflacodepr Posted August 6, 2008 Share Posted August 6, 2008 the SET stated is incomplete, you must provide what to set.. $sql = "UPDATE aiimjoin SET company = 'YOUR COMPANY' WHERE uid = "$_SESSION[uid]""; Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609707 Share on other sites More sharing options...
trq Posted August 6, 2008 Share Posted August 6, 2008 the SET stated is incomplete, you must provide what to set.. $sql = "UPDATE aiimjoin SET company = 'YOUR COMPANY' WHERE uid = "$_SESSION[uid]""; This will not cause a php syntax error. Can we see your current code? Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609709 Share on other sites More sharing options...
ChompGator Posted August 6, 2008 Author Share Posted August 6, 2008 Yep, here it is: this is handle.php // The form.php is below it <?php session_start(); $host="***"; // Host name $username="***"; // Mysql username $password="***"; // Mysql password $db_name="***"; // Database name // Connect to DB $db = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($db_name); $sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = "$_SESSION[uid]""; // Step 3 $result = mysql_query($sql) or die ( mysql_error() ); ?> form.php <form method="post" action="handle.php"<br> <td style="width: 175px;" valign="top"><font face="Verdana" size="2"> <strong>Company Name:<br><input type=""text" AutoFill" tabindex="1" maxlength="25" size="20" name="company"> </strong></font></td><br> <td style="width: 175px;" valign="top"><font face="Verdana" size="2"> <strong>Company Address:<Br><input type="text" tabindex="1" maxlength="25" size="20" name="address"> </strong></font></td><br> <td style="width: 175px;" valign="top"><font face="Verdana" size="2"> <strong>Phone Number:<br><input type="text" tabindex="1" maxlength="25" size="20" name="phone"> </strong></font></td><br> <input type="submit" value="Change Profile" /> </form> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609714 Share on other sites More sharing options...
ChompGator Posted August 6, 2008 Author Share Posted August 6, 2008 Im only trying to update on of the fields right now as soon as I get it working, Ill add in the UPDATE for the rest of the fields Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609717 Share on other sites More sharing options...
xstevey_bx Posted August 6, 2008 Share Posted August 6, 2008 Replace $db = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error()); with mysql_connect ( $host, $username, $password)or die("Could not connect: ".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609722 Share on other sites More sharing options...
trq Posted August 6, 2008 Share Posted August 6, 2008 You cannot use double quotes within a double quoted string without escaping them. This line could be... $sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = \"$_SESSION[uid]\""; But thats still not the best solution because associative indexes also should be surrounded by quotes. Try... $sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = '{$_SESSION['uid']}'"; You also really ought be sanatising any variables use din queries with mysql_real_escape_string(). Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609723 Share on other sites More sharing options...
ChompGator Posted August 6, 2008 Author Share Posted August 6, 2008 AAlright, here is the new code: Getting a "No Database Selected" Other than that, Parse errors have disappeared, thank you for all the help and advice! <?php session_start(); $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="login"; // Database name // Connect to DB mysql_connect ( $host, $username, $password, $db_name)or die("Could not connect: ".mysql_error()); $sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = '{$_SESSION['uid']}'"; // Step 3 $result = mysql_query($sql) or die ( mysql_error() ); ?> Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609909 Share on other sites More sharing options...
trq Posted August 6, 2008 Share Posted August 6, 2008 You have no call to mysql_select_db(). Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-609928 Share on other sites More sharing options...
ChompGator Posted August 6, 2008 Author Share Posted August 6, 2008 One last problem...Ok, I have it so it updates now, however the form submits, I dont get any errors, handle.php is the php script that does the updating, however after filling out the form and clicking "update profile" - it doesn't update the fields in phpmyadmin ....Any advice? handle.php // Supposed to update the fields in the db table. <?php session_start(); $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name // Connect to DB mysql_connect ( $host, $username, $password, $db_name)or die("Could not connect: ".mysql_error()); mysql_select_db($db_name); $sql = "UPDATE aiimjoin SET company = 'company' WHERE uid = '{$_SESSION['uid']}'"; // Step 3 $result = mysql_query($sql) or die ( mysql_error() ); ?> Link to comment https://forums.phpfreaks.com/topic/118448-parse-errors/#findComment-610081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.