brem13 Posted February 17, 2009 Share Posted February 17, 2009 ok, ive got a mysql database that stores all the comments for pictures, im trying to create a script that will update the comment fields when the form is submitted, the error i get is "Warning: Invalid argument supplied for foreach() in /home/fotoecli/public_html/galleries/members/BREMINEM/RANDOM/editgall.php on line 51" -line 51 is the foreach statement i know it is not the best code but all i want to do is update those fields in the mysql database, code is below..... thank you!!! <?php if ($_POST['submit']) { include("../../../../configpic.php"); $username = $_COOKIE['loggedin']; $comment = $_POST['comment[]']; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $result = mysql_query("SELECT * FROM $table"); // Count table rows $count = mysql_num_rows($result); foreach($count as $id){ mysql_query("UPDATE $table SET comment='$comment' WHERE picture='$file'"); } } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Fotoeclipse.com - User Album</title> </head> <BODY> <?php include("../../../../header.php"); ?> <table style="width: 100%"> <tr> <td style="width: 65%" valign="top"> <? function is_img($input) { $ext = substr($input, -4, 4); if(strtolower($ext) == ".jpg") return true; if(strtolower($ext) == ".png") return true; if(strtolower($ext) == ".gif") return true; if(strtolower($ext) == "jpeg") return true; if(strtolower($ext) == ".bmp") return true; return false; } $targetpath = "."; $target = $targetpath; $cwd = $target; $dir=""; $files=""; $cwd1 = getcwd(); $cwd1 = explode("/", $cwd1); $pwd = $cwd1[(count($cwd1)-2)]; $pwd = strtolower($pwd); echo "<table border=5 BORDERCOLORLIGHT=#EEEEEE BORDERCOLORDARK=#0000CC rules=all cellspacing=6 cellpadding=15 align='center'><tr>"; if ($handle = opendir($cwd)) { /* Read file names */ while (false !== ($file = readdir($handle))) { if (true == is_dir("$cwd$file")) { } else { if(true == is_img($cwd.$file)) { $c++; echo '<td align=center>'; echo '<a href="'.$cwd.'/'.$file.'"><img src="'.$cwd.'/thumbs/'.$file.'"></a><br>'; ?> <form name="comments" action="editgall.php" method="POST"> <font face="tahoma" size="1">Edit: </font> <input type="text" name="comment[]" id="comment1" value="<?php include("../../../../configpic.php"); mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); $result = mysql_db_query($database, "SELECT * FROM $pwd WHERE picture='$file'") or die (mysql_error()); while ($qry = mysql_fetch_array($result)) { echo "$qry[comment]"; } ?>"> <? echo '</td>'; if ($c==4) { echo '</tr><tr>'; $c=0;} } } } closedir($handle); } echo '</tr></table>'; ?> <input type="submit" name="submit" value="update"> </form> <?php include("../../../../footer.php"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/145622-update-multiple-mysql-fields/ Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 $count is not an array so you can't use foreach ... try a for or while loop instead ;-) Quote Link to comment https://forums.phpfreaks.com/topic/145622-update-multiple-mysql-fields/#findComment-764497 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.