Jump to content

updating mysql database


brem13

Recommended Posts

ok, another question, sorry.

im still kind of new to this kind of stuff.

i have a script that will loop through a folder and display all the pictures in that folder, all of those pictures filenames are in a mysql database with comment fields. im trying to update the comments in the mysql database when i click on update with all the update comments. but it doesnt do anything. i think it has something to do with the files being looped and put in arrays. anyone have any pointers for me please?

here is the script that is  looping through the directory,displaying the pictures on the page with the comment textbox underneath, and the form to update the mysql database. any help at all will be greatly appreciated

------------------------------------------------------------------------------------------

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 "<br>".$file."<br>\n";

    echo '</td>';

    if ($c==4) { echo '</tr><tr>'; $c=0;}

    }

}

 

  }

  closedir($handle);

}

echo '</tr></table>';

?>

<input type="submit" name="submit" value="update">

</form>

Link to comment
https://forums.phpfreaks.com/topic/147954-updating-mysql-database/
Share on other sites

I didn't bother to read your code, but a simple SQL query to update a MySQL database would be as follows:


// $link - would of course be your database connection

$data = $_POST['data'];

$sql="UPDATE ".$table." SET field='".$data."' WHERE field='whatever'";

mysql_query($sql,$link) or die( 'Error: ' . mysql_error() );

mysql_close($link);


 

You could keep writing them out. :D

 

or maybe you can do something like this... but I've never had this problem, and I'm not sure how it would work.


$datas = array ('$_POST['data']', 'etc...');
$fields = array ('field1', 'field2');
$wheres = array('whereatfirst', 'whereatsecond');

foreach ($datas as $d, $fields as $f, $wheres as $w)
{

$sql="UPDATE ".$table." SET ".$f."='".$d."' WHERE field='".$w."'";

mysql_query($sql,$link) or die( 'Error: ' . mysql_error() );

mysql_close($link);

}

 

I honestly don't know if that would work, and I just added the where's as a second; if you don't need that, you don't need that.

 

I have to go, but I have a piece of code I wrote from before that might be helpful to you:

$sql="INSERT INTO ".$releasestable." (series, type, chapter, language, scanlator, download1, download2, download3, notes, owner, video)
VALUES ('$_POST[series]', '".$aomvar."', '$_POST[chapter]', '$_POST[language]', '$_POST[scanlator]', '$_POST[download1]', '$_POST[download2]', '$_POST[download3]', '$_POST[notes]', '".$usersname."', '$_POST[video]')";

 

seems mysql can use arrays... though, that code above still won't fix your problem, you may be able to figure something out with that theory.

Archived

This topic is now archived and is closed to further replies.

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