brem13 Posted March 6, 2009 Share Posted March 6, 2009 hey, i have a script where im going through a mysql database and displaying comments for pictures for that pictures' filename. im trying to write a script where i can update the comments for the pictures. what i have now is a page that will go through the mysql database and show pictures that are only in that album and it will also show the comment right next in an input tag. now if i change the comment and click on update, it runs the update script but nothing changes in the database and the page stays the same. can someone help me where i went wrong? code is below. Thank you <?php if ($_POST['submit']) { include("../../../../configpic.php"); $username = $_COOKIE['loggedin']; $userlow = strtolower($username); $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 $userlow"); $transaction = mysql_query("SELECT * FROM $userlow") or die (mysql_error()); $p = 1; while($trans = @mysql_fetch_array($transaction)){ mysql_query("UPDATE $userlow SET comment='comment[".$p."]' WHERE picture='$qry[picture]'"); $p++; } } ?> <?php include("../../../../configpic.php"); $username1 = basename(dirname(__FILE__)) ; $cwd = getcwd(); $cwd = explode("/", $cwd); $pwd = $cwd[(count($cwd)-2)]; $userdir = strtolower($pwd); $username2 = strtolower($username1); $featured = "Yes"; mysql_connect($server, $db_user, $db_pass) or die (mysql_error()); $result = mysql_db_query($database, "select * from $userdir WHERE album = '$username1'") or die (mysql_error()); $folder = "galleries/members/".$username1; echo "<p align=center>"; $x = 1; $p = 1; while ($qry = mysql_fetch_array($result)) { echo '<a href="'.$qry[picture].'"><img src="'.'thumbs/'.$qry[picture].'"></a>'; echo "<form name='edit' action='editgall.php' method='POST'><input type='text' name='comment[".$p."]' length='50' value=".$qry[comment].">"; $p++; if($x == 4) { echo '<br />'; $x = 0; } $x++; } echo "</p>"; echo "<input type='submit' name='submit' value='Update'></form>"; ?> Link to comment https://forums.phpfreaks.com/topic/148178-mysql-database-update-multiple-fields/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.