liamloveslearning Posted September 27, 2010 Share Posted September 27, 2010 Hi all, Im having some trouble trying to update my table using an array, It processes and doesnt throw up any errors so im at a loss as to whats happening as its not updating my table? my page is mysql_select_db($database_saucy_connection, $saucy_connection); $query_allphotos = "SELECT * FROM model_login, model_pictures WHERE model_pictures.user_id=model_login.id"; $allphotos = mysql_query($query_allphotos, $saucy_connection) or die(mysql_error()); $row_allphotos = mysql_fetch_assoc($allphotos); $totalRows_allphotos = mysql_num_rows($allphotos); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center">Picture Name</td> <td align="center">Upload Date</td> <td align="center"><strong>No Downloads</strong></td> <td align="center"> Approved? </td> <td align="center"> Hunnies Gallery </td> <td align="center"> Hunks Gallery </td> <td align="center"> Default Pic </td> <td align="center"> Theme Pic </td> <td align="center"> Homepage Pic </td> </tr> <?php while($rows=mysql_fetch_array($allphotos)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><? $user_picture[]=$rows['user_picture']; ?><?php echo $rows['user_picture']; ?></td> <td align="center"><? $user_picture_date[]=$rows['user_picture_date']; ?><?php echo $rows['user_picture_date']; ?></td> <td align="center"><? $picture_downloads[]=$rows['picture_downloads']; ?><?php echo $rows['picture_downloads']; ?></td> <td align="center"><? $user_pic_approval[]=$rows['user_pic_approval']; ?><?php echo $rows['user_pic_approval']; ?> </td> <td align="center"><? $hotties_gallery[]=$rows['hotties_gallery']; ?><?php echo $rows['hotties_gallery']; ?> </td> <td align="center"><? $hunks_gallery[]=$rows['hunks_gallery']; ?><?php echo $rows['hunks_gallery']; ?> </td> <td align="center"><? $default_pic[]=$rows['default_pic']; ?><?php echo $rows['default_pic']; ?> </td> <td align="center"><? $theme_gallery[]=$rows['theme_gallery']; ?><?php echo $rows['theme_gallery']; ?> </td> <td align="center"><? $homepage=$rows['homepage_pic']; ?><?php echo $rows['homepage_pic']; ?> </td> </tr> <?php } ?> <tr> <td colspan="5" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $model_pictures SET user_pic_approval='$user_pic_approval[$i]', hotties_gallery='$hotties_gallery[$i]', hunks_gallery='$hunks_gallery[$i]', default_pic='$default_pic[$i]', theme_gallery='$theme_gallery[$i]', homepage_pic='$homepage_pic[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } Link to comment https://forums.phpfreaks.com/topic/214557-update-record-using-array/ Share on other sites More sharing options...
nightkarnation Posted September 27, 2010 Share Posted September 27, 2010 I am having the exact same problem but using a different method of array: $result = mysql_query("UPDATE `offers` SET qty_purchased = (qty_purchased + 1) WHERE purchase_id = '$produtos[0]['ProdID']'"); ...Not working for me But echo $produtos[0]['ProdID']; //works! Any ideas? Link to comment https://forums.phpfreaks.com/topic/214557-update-record-using-array/#findComment-1116479 Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2010 Share Posted September 27, 2010 Unless this script has more to it, or relies on register_globals = On (which is a bad idea), if($Submit) will never evaluate to TRUE unless you assign it a value. It should probably be changed to if($_POST['Submit']). Link to comment https://forums.phpfreaks.com/topic/214557-update-record-using-array/#findComment-1116485 Share on other sites More sharing options...
liamloveslearning Posted September 27, 2010 Author Share Posted September 27, 2010 Still no luck! Im also trying to implement checkboxes now which are checked dependant on the value but this doesnt seem to be working neither :@ <?php require_once('Connections/saucy_connection.php'); ?> <?php $checkbox = '0'; if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_saucy_connection, $saucy_connection); $query_allphotos = "SELECT * FROM model_login, model_pictures WHERE model_pictures.user_id=model_login.id"; $allphotos = mysql_query($query_allphotos, $saucy_connection) or die(mysql_error()); $row_allphotos = mysql_fetch_assoc($allphotos); $totalRows_allphotos = mysql_num_rows($allphotos); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center">Picture Name</td> <td align="center">Upload Date</td> <td align="center"><strong>No Downloads</strong></td> <td align="center"> Approved? </td> <td align="center"> Hunnies Gallery </td> <td align="center"> Hunks Gallery </td> <td align="center"> Default Pic </td> <td align="center"> Theme Pic </td> <td align="center"> Homepage Pic </td> </tr> <?php while($rows=mysql_fetch_array($allphotos)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><? $user_picture[]=$rows['user_picture']; ?><?php echo $rows['user_picture']; ?></td> <td align="center"><? $user_picture_date[]=$rows['user_picture_date']; ?><?php echo $rows['user_picture_date']; ?></td> <td align="center"><? $picture_downloads[]=$rows['picture_downloads']; ?><?php echo $rows['picture_downloads']; ?></td> <td align="center"><? $user_pic_approval[]=$rows['user_pic_approval']; ?> <input type='checkbox' name='checkbox' value='<?php echo $rows['user_pic_approval']; ?>'/> </td> <td align="center"><? $hotties_gallery[]=$rows['hotties_gallery']; ?><input type='checkbox' name='checkbox' value=' <?php echo $rows['hotties_gallery']; ?> '/> </td> <td align="center"><? $hunks_gallery[]=$rows['hunks_gallery']; ?> <input type='checkbox' name='checkbox' value='<?php echo $rows['hunks_gallery']; ?>'/> </td> <td align="center"><? $default_pic[]=$rows['default_pic']; ?><input type='checkbox' name='checkbox' value='<?php echo $rows['default_pic']; ?>'/> </td> <td align="center"><? $theme_gallery[]=$rows['theme_gallery']; ?><input type='checkbox' name='checkbox' value='<?php echo $rows['theme_gallery']; ?> '/> </td> <td align="center"><? $homepage=$rows['homepage_pic']; ?><input type='checkbox' name='checkbox' value='<?php echo $rows['homepage_pic']; ?>'/> </td> </tr> <?php } ?> <tr> <td colspan="5" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($_POST['Submit']) { if (isset($_POST['checkbox'])) { if ($checkbox == '1') { $ch1 = 'checked'; } } for($i=0;$i<$count;$i++){ $sql1="UPDATE $model_pictures SET user_pic_approval='$user_pic_approval[$i]', hotties_gallery='$hotties_gallery[$i]', hunks_gallery='$hunks_gallery[$i]', default_pic='$default_pic[$i]', theme_gallery='$theme_gallery[$i]', homepage_pic='$homepage_pic[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } ?> </body> </html> <?php mysql_free_result($allphotos); ?> Link to comment https://forums.phpfreaks.com/topic/214557-update-record-using-array/#findComment-1116498 Share on other sites More sharing options...
Pikachu2000 Posted September 27, 2010 Share Posted September 27, 2010 I am having the exact same problem but using a different method of array: $result = mysql_query("UPDATE `offers` SET qty_purchased = (qty_purchased + 1) WHERE purchase_id = '$produtos[0]['ProdID']'"); ...Not working for me But echo $produtos[0]['ProdID']; //works! Any ideas? Your problem should be in a thread of its own, but try this. $result = mysql_query("UPDATE `offers` SET qty_purchased = (qty_purchased + 1) WHERE purchase_id = '{$produtos[0]['ProdID']}'"); And it's much better not to form the query string in the query execution. Form it in a variable, then use the variable in the execution. That way you have more debugging options when it becomes necessary, such as it just did. $query = "SELECT whatever FROM table"; $result = mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/214557-update-record-using-array/#findComment-1116502 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.