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!!! any help getting this fixed is greatly appreciated <?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"); foreach($id 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 Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 You can't use $id as $id in your foreach Try $id as $value instead and see if that solves it Quote Link to comment Share on other sites More sharing options...
brem13 Posted February 17, 2009 Author Share Posted February 17, 2009 nope, didnt work, im not too good with loops and stuff, im kindof stumped Quote Link to comment Share on other sites More sharing options...
drisate Posted February 17, 2009 Share Posted February 17, 2009 Your missing something here $result = mysql_query("SELECT * FROM $table"); You make a select but do nothing with it foreach($id as $id){ mysql_query("UPDATE $table SET comment='$comment' WHERE picture='$file'"); And loop $id but it was never initialized Try something like this Replace the foreach by this code $transaction = mysql_query("SELECT * FROM $table") or die (mysql_error()); while($trans = @mysql_fetch_array($transaction)){ [...] } That will loop every rows of $table Quote Link to comment Share on other sites More sharing options...
brem13 Posted February 17, 2009 Author Share Posted February 17, 2009 ok, that eliminated the error, but its not updating, hmm....? Quote Link to comment 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.