timmah1 Posted December 24, 2008 Share Posted December 24, 2008 Can someone tell me why this only updates one field? $id = $loginrow['id']; $val1 = $val; $count = count($id); for ($i = 0; $i < $count; $i++) { $id1 = $id[$i]; //$package1 = $val1[$i]; $sql1 = mysql_query("UPDATE dailypicks1 SET picks = '$val1', sport = '$sport', active = '$active', month_spl = '$spl_date', time_spl = '$endtime' WHERE id = '$id1'"); mysql_query($sql1) or die("Sorry, there was a problem UPDATING your account ".mysql_error()); } It'll update one field, but then give me an error Sorry, there was a problem UPDATING your account 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 '1' at line 1 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/138340-solved-multiple-updates/ Share on other sites More sharing options...
revraz Posted December 24, 2008 Share Posted December 24, 2008 You are running the query twice. Either change $sql1 to remove mysql_query or remove the mysql_query($sql1) on the next line. $sql1 = mysql_query("UPDATE dailypicks1 SET picks = '$val1', sport = '$sport', active = '$active', month_spl = '$spl_date', time_spl = '$endtime' WHERE id = '$id1'"); mysql_query($sql1) Link to comment https://forums.phpfreaks.com/topic/138340-solved-multiple-updates/#findComment-723367 Share on other sites More sharing options...
timmah1 Posted December 24, 2008 Author Share Posted December 24, 2008 I'm sorry, I'm not following Link to comment https://forums.phpfreaks.com/topic/138340-solved-multiple-updates/#findComment-723369 Share on other sites More sharing options...
timmah1 Posted December 24, 2008 Author Share Posted December 24, 2008 This is the code //check the database to see if this is an update $loginsql = "SELECT * FROM dailypicks1 WHERE sport = '$sport' AND package = '$name'"; $loginres = mysql_query($loginsql); //$numrows = mysql_num_rows($loginres); $loginrow = mysql_fetch_assoc($loginres); if($loginrow['active'] == $active) { $id = $loginrow['id']; $val1 = $val; $count = count($id); for ($i = 0; $i < $count; $i++) { $id1 = $id[$i]; //$package1 = $val1[$i]; $sql1 = mysql_query("UPDATE dailypicks1 SET picks = '$val1', active = '$active', month_spl = '$spl_date', time_spl = '$endtime' WHERE id = '$id1'") or die("Sorry, there was a problem UPDATING your account ".mysql_error()); } } Link to comment https://forums.phpfreaks.com/topic/138340-solved-multiple-updates/#findComment-723370 Share on other sites More sharing options...
revraz Posted December 24, 2008 Share Posted December 24, 2008 Change $sql1 = mysql_query("UPDATE dailypicks1 SET picks = '$val1', sport = '$sport', active = '$active', month_spl = '$spl_date', time_spl = '$endtime' WHERE id = '$id1'"); mysql_query($sql1) or die("Sorry, there was a problem UPDATING your account ".mysql_error()); to $sql1 = ("UPDATE dailypicks1 SET picks = '$val1', sport = '$sport', active = '$active', month_spl = '$spl_date', time_spl = '$endtime' WHERE id = '$id1'"); mysql_query($sql1) or die("Sorry, there was a problem UPDATING your account ".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/138340-solved-multiple-updates/#findComment-723371 Share on other sites More sharing options...
timmah1 Posted December 24, 2008 Author Share Posted December 24, 2008 I got it. I had to change $sql1 = mysql_query("UPDATE dailypicks1 SET picks = '$val1', active = '$active', month_spl = '$spl_date', time_spl = '$endtime' WHERE id = '$id1'") to $sql1 = mysql_query("UPDATE dailypicks1 SET picks = '$val1', active = '$active', month_spl = '$spl_date', time_spl = '$endtime' WHERE id = '$id'") Thank you for your help. Without that, it wouldn't update properly. Thank you again revraz Link to comment https://forums.phpfreaks.com/topic/138340-solved-multiple-updates/#findComment-723373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.