Jump to content


Photo

PHP/MySQL 4.0 to MySQL 5.0: ForEach problems


  • Please log in to reply
1 reply to this topic

#1 NiallAA

NiallAA

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 25 June 2013 - 08:51 AM

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


#2 dalecosp

dalecosp

    Advanced Member

  • Members
  • PipPipPip
  • 306 posts
  • LocationJoplin, MO

Posted 25 June 2013 - 09:09 AM

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).
"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com