jcstanley Posted January 16, 2008 Share Posted January 16, 2008 Hi I am having trouble trying to update a number of columns. I originally used the script to update just 2 columns using the following code, which works fine: $query = "UPDATE members SET available = $available, required = $required WHERE email=$email"; I then decided that more columns needed to be included and changed the coded to: $query = "UPDATE members SET available = $available, required = $required, datesav = $datesav prevexperience = $prevexperience, datesneed = $datesneed, experienceneed = $experienceneed WHERE email=$email"; but it doesnt work - I use an IF statement if(!$result) and get my custom error message. Full coded listed below: $avail = $_POST['available']; $req = $_POST['required']; $datesav = $_POST['Dates_Av']; $prevexperience = $_POST['Prev_Experience']; $datesneed = $_POST['Dates_Needed']; $experienceneed = $_POST['Experience_Needed']; //(Check that variables contain values, which they do) echo $datesav; echo $prevexperience; echo $datesneed; echo $experienceneed; include ('connect.php'); $query = "UPDATE members SET available = $available, required = $required, datesav = $datesav prevexperience = $prevexperience, datesneed = $datesneed, experienceneed = $experienceneed WHERE email=$email"; $result = mysql_query($query, $dbh); if(!$result) { echo'<p style="margin-top: 0; margin-bottom: 0"> </p>'; echo'<p style="margin-top: 0; margin-bottom: 0"> </p>'; echo '<center><p><b><font face="arial" size="2" color="#ff0000">Status could not be changed.</b></font></p>'; exit; } else { echo'<p style="margin-top: 0; margin-bottom: 0"> </p>'; echo'<p style="margin-top: 0; margin-bottom: 0"> </p>'; echo '<center><p><b><font face="arial" size="2" color="#ff0000">Update Successful.</b></font></p>'; } Any suggestions welcome Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/86293-solved-problem-with-updating-multiple-columns/ Share on other sites More sharing options...
rajivgonsalves Posted January 16, 2008 Share Posted January 16, 2008 you forgot a comma, this $query = "UPDATE members SET available = $available, required = $required, datesav = $datesav prevexperience = $prevexperience, datesneed = $datesneed, experienceneed = $experienceneed WHERE email=$email"; should be $query = "UPDATE members SET available = $available, required = $required, datesav = $datesav, prevexperience = $prevexperience, datesneed = $datesneed, experienceneed = $experienceneed WHERE email=$email"; also are all of your columns intergers ? Quote Link to comment https://forums.phpfreaks.com/topic/86293-solved-problem-with-updating-multiple-columns/#findComment-440829 Share on other sites More sharing options...
jcstanley Posted January 16, 2008 Author Share Posted January 16, 2008 thanks for spotting the comma. Only 'available' and 'required' are integers, the rest are text. Quote Link to comment https://forums.phpfreaks.com/topic/86293-solved-problem-with-updating-multiple-columns/#findComment-440831 Share on other sites More sharing options...
rajivgonsalves Posted January 16, 2008 Share Posted January 16, 2008 you have to single quote them then... Quote Link to comment https://forums.phpfreaks.com/topic/86293-solved-problem-with-updating-multiple-columns/#findComment-440837 Share on other sites More sharing options...
cooldude832 Posted January 16, 2008 Share Posted January 16, 2008 for the most part you can single quote everything in mysql and not have a problem and not forget then Quote Link to comment https://forums.phpfreaks.com/topic/86293-solved-problem-with-updating-multiple-columns/#findComment-440838 Share on other sites More sharing options...
jcstanley Posted January 16, 2008 Author Share Posted January 16, 2008 still no joy. this is what the query looks like now: $query = "UPDATE members SET available = $available, required = $required, datesav = '$datesav', prevexperience = '$prevexperience', datesneed = '$datesneed', experienceneed = '$experienceneed' WHERE email='$email'"; Quote Link to comment https://forums.phpfreaks.com/topic/86293-solved-problem-with-updating-multiple-columns/#findComment-440839 Share on other sites More sharing options...
cooldude832 Posted January 16, 2008 Share Posted January 16, 2008 well lets actually put on the mysql error reporting <?php $result = mysql_query($query, $dbh) or die(mysql_error()."<br /><br />".$query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86293-solved-problem-with-updating-multiple-columns/#findComment-440841 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.