Jump to content

update record using array


liamloveslearning

Recommended Posts

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
Share on other sites

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
Share on other sites

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