Jump to content

PHP/MySQL 4.0 to MySQL 5.0: ForEach problems


NiallAA

Recommended Posts

The following piece of code updated rows of data when my database was on MySQL 4.0

 

Now on MySQL 5.0, it does not work.  Can anyone offer some help as to why?

	foreach($_POST['mid'] as $key=>$val) 
	{ 
	
	$percent = $_POST['percent'];
	$detail = $_POST['detail'];
	$qty = $_POST['qty'];
	$rate = $_POST['rate'];
	
   	mysql_query("UPDATE val_mworks SET
		mworks_percent = '$percent[$key]',
		mworks_detail = '$detail[$key]',
		mworks_qty = '$qty[$key]',
		mworks_rate = '$rate[$key]'
		WHERE mworks_id = '$val'
		") or die(mysql_error());   
	} 

I'm afraid I can't help based on that alone. For example, what does "It does not work" mean? Do you see a blank page in the browser? Do you receive an error message? Do smoke pour out of the server and choke the SysOp? :D

 

And, ouch, die() as your only error handler? I guess that depends on some other factors ... if it's in house or development only, that's a quick and dirty way to handle the failure, I guess.

 

To help you with debugging, how about something more like?

 

foreach($_POST['mid'] as $key=>$val)
{

$percent = $_POST['percent'];
$detail = $_POST['detail'];
$qty = $_POST['qty'];
$rate = $_POST['rate'];

$sql = "UPDATE val_mworks SET
mworks_percent = '$percent[$key]',
mworks_detail = '$detail[$key]',
mworks_qty = '$qty[$key]',
mworks_rate = '$rate[$key]'
WHERE mworks_id = '$val'
";

$result = mysql_query($sql);

if (!$result) {
   echo "MySQL Query Failed!
   SQL was : $sql
   MySQL said : ".mysql_error();
   die();
}

}
And if that doesn't get you any answers, I'd check logs and possibly open a ticket with your host? (Assuming you have a hosting service, of course).

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.