Forum Moderators: coopster

Message Too Old, No Replies

Update Woes

         

Esqulax

9:11 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



Hiya.. im trying to get my database update, but its being stubborn.

Heres what i got:


echo('<form method="post" action="'.$self.'">');
$upid = $_POST['carid'];
$how_many=count($upid);
$reg =$_POST['reg'];

if ($how_many>0)
{
echo ("You chose the following records:<br>");

for ($i=0; $i<$how_many; $i++)
{
$sql = "SELECT * FROM cars WHERE car_id = '$upid[$i]'";
$rs1=(mysql_query($sql,$conn));

while($row = mysql_fetch_array($rs1)){
echo (($i+1) . " - " . $upid[$i]. $row['car_id']."<br>");
echo ("<input type=\"hidden\" name=\"updateid[]\" value=\"{$upid[$i]}\"> ");
echo ('Reg No:<input type="text" name="reg" size="8" value="'.$row["reg_no"].'"><br>');
}
}

echo("Ok to update ".$how_many." record(s)?");
echo('<input type="submit" name="submit" value="Yes">');

echo('</form>');
}
foreach($updateid as $val1)
{
$sql3="UPDATE cars SET reg_no= '$reg' WHERE car_id ='$val1'";
mysql_query($sql3);
}

The error i get says:
Warning: Invalid argument supplied for foreach() in editcar.php on line 73

but im pretty sure i activated that array a little above.. any ideas?

eelixduppy

12:50 am on Feb 26, 2008 (gmt 0)



Are you sure that in the foreach statement $updateid shouldn't be $upid? $updateid has to be an array otherwise you are going to get that warning, too. To check for that you'd have to use is_array [php.net]() before the foreach to determine whether or not to use it.

Esqulax

11:47 am on Feb 26, 2008 (gmt 0)

10+ Year Member



Thats exactly what the issue was.. i diddnt $_POST it at the top.
Happens when you stare at code constantly for hours :)