brem13 Posted March 4, 2009 Share Posted March 4, 2009 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 More sharing options...
alphanumetrix Posted March 4, 2009 Share Posted March 4, 2009 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); Link to comment https://forums.phpfreaks.com/topic/147954-updating-mysql-database/#findComment-776542 Share on other sites More sharing options...
brem13 Posted March 4, 2009 Author Share Posted March 4, 2009 thank you, but im trying to update multiple fields from an array Link to comment https://forums.phpfreaks.com/topic/147954-updating-mysql-database/#findComment-776548 Share on other sites More sharing options...
alphanumetrix Posted March 4, 2009 Share Posted March 4, 2009 You could keep writing them out. 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. Link to comment https://forums.phpfreaks.com/topic/147954-updating-mysql-database/#findComment-776567 Share on other sites More sharing options...
alphanumetrix Posted March 4, 2009 Share Posted March 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/147954-updating-mysql-database/#findComment-776575 Share on other sites More sharing options...
brem13 Posted March 4, 2009 Author Share Posted March 4, 2009 ok, thanks for the help Link to comment https://forums.phpfreaks.com/topic/147954-updating-mysql-database/#findComment-776604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.