Jump to content

updating multiple mysql entries


brem13

Recommended Posts

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>

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.