Jump to content

[SOLVED] Multiple Updates


timmah1

Recommended Posts

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

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)

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());

		}
	}

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());

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.