jmif96 Posted May 8, 2006 Share Posted May 8, 2006 Hey guys,I can't seem to get this script to update a record in my MySQL database for me. It takes input from a form (POST) and assigns them variables. It then connects to the database, assigns the query to $query, and runs the query inside of an if statement to test if it worked. But I keep getting an error and when I check the database it hasn't updated.Here's part of the code:$query = "UPDATE Users SET AIM = '$AIM', YIM = '$YIM', MSN = '$MSN', website = '$website', Location = '$location', RW_Expirence = '$RW_Expirence', VATSIM ID = '$VATSIM', Auto = '$auto' WHERE `First` = '$First' AND Last = '$Last'";if (mysql_query($query)) {print "Your profile has been updated.";?><form> <input type="button" value="Run Again" onClick="window.location = 'profile.php'"></form><?php}else {print ("Uh Oh! There was an error, please try again.");?><form><input type="button" value="Run Again" onClick="window.location = 'profile.php'"></form><?php}mysql_close();?>Any help is appreciated, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/ Share on other sites More sharing options...
.josh Posted May 9, 2006 Share Posted May 9, 2006 do this:mysql_query($query) or die(mysql_error());and post what the error is.also do this:echo $query;and post what it echos, as well.(this should probably be in the php forum, btw) Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/#findComment-34511 Share on other sites More sharing options...
datamodeler Posted May 9, 2006 Share Posted May 9, 2006 [!--quoteo(post=372453:date=May 8 2006, 07:28 PM:name=John Dunne)--][div class=\'quotetop\']QUOTE(John Dunne @ May 8 2006, 07:28 PM) [snapback]372453[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hey guys,I can't seem to get this script to update a record in my MySQL database for me. It takes input from a form (POST) and assigns them variables. It then connects to the database, assigns the query to $query, and runs the query inside of an if statement to test if it worked. But I keep getting an error and when I check the database it hasn't updated.Here's part of the code:$query = "UPDATE Users SET AIM = '$AIM', YIM = '$YIM', MSN = '$MSN', website = '$website', Location = '$location', RW_Expirence = '$RW_Expirence', VATSIM ID = '$VATSIM', Auto = '$auto' WHERE `First` = '$First' AND Last = '$Last'";if (mysql_query($query)) {print "Your profile has been updated.";?><form> <input type="button" value="Run Again" onClick="window.location = 'profile.php'"></form><?php}else {print ("Uh Oh! There was an error, please try again.");?><form><input type="button" value="Run Again" onClick="window.location = 'profile.php'"></form><?php}mysql_close();?>Any help is appreciated, thanks![/quote]The correct form for an update statement is:update tablenameset columnname = value [, columnname = value ...]where primarykey = pk_valueand you left off the last part. Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/#findComment-34518 Share on other sites More sharing options...
jmif96 Posted May 9, 2006 Author Share Posted May 9, 2006 Thanks for your help guys, turns out it didn't know here to place the data because I used the $_POST to get the vars. So that messed up the header, thus messing up some session variables which I was using to place the table.Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/#findComment-34783 Share on other sites More sharing options...
jmif96 Posted May 10, 2006 Author Share Posted May 10, 2006 Actually, I do have a question.When I submit the form I send it to xxx.php?ID=USER ID (taken from session).And when I do this and run it the update works but if you just logged in and ran it for the first time during that session, you get this error:Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0However, it still updates the record, and when you run the script again, it dosen't come up. Is there any way to prevent that message? Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/#findComment-34784 Share on other sites More sharing options...
fenway Posted May 10, 2006 Share Posted May 10, 2006 Well, the error message itself tells you how to turn it off... but it sounds like you should a) not use global variables for the session and b) upgrade your version of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/#findComment-34944 Share on other sites More sharing options...
jmif96 Posted May 11, 2006 Author Share Posted May 11, 2006 Just to be sure, you turn it off in your php.ini file correct? Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/#findComment-35139 Share on other sites More sharing options...
fenway Posted May 13, 2006 Share Posted May 13, 2006 Sounds like it. Quote Link to comment https://forums.phpfreaks.com/topic/9349-updating-a-table-with-php/#findComment-35514 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.