Jump to content

Updating multiple sql records


phily245

Recommended Posts

I have a problem with an amend to an admin system I am trying to change. The shop stocks different colours of each product and the client wants to be able to update the stock levels of all colours of one product (which all share the same title) on one form. I have tried following some instructions on some sites and tried making my own and I can get it to display the form and the values correctly, but on submission it does nothing but direct me to a page without a title value in the address (e.g. www.example.com/example/stock_level_2.php?title=). I think it may be to do with the arrays I am using, has anyone got any ideas? Here is the code.

 

Form:

<?php
$pd_title = str_replace("_"," ",$_REQUEST["title"]);
$pd_title = str_replace("%","&#37;",$pd_title);
$pd_title = str_replace("/","&#47;",$pd_title);

$lookupqueryc = mysql_query("SELECT * FROM product WHERE pd_title = '".$pd_title."' ORDER BY pd_id DESC");

echo '<table><tr><th align="center" class="bodytext">Product<br />ID</th><th align="center" class="bodytext">Product Name</th><th align="center" class="bodytext">Stock Level</th></tr>';

$form = '<form name="frmAmendStock" method="post" action="stock_level_2.php?title="';
$form .=  $_GET["title"];
$form .= '" enctype="multipart/form-data">';
echo $form;
echo '<input name="submitted" type="hidden" value="true">';
$count=mysql_num_rows($lookupqueryc);
echo '<input name="count" type="hidden" value="';
echo $count;
echo '">';

                          
		  while($lookupresultc = mysql_fetch_array($lookupqueryc)){  
		  
		        

			echo '<tr><td align="center" class="bodytext">';
                                $id[]=$lookupresultc["pd_id"];
			echo $lookupresultc["pd_id"];
			echo '</td><td class="bodytext">';
			echo $lookupresultc["pd_title"];
			if (isset($lookupresultc["pd_colour"]) && $lookupresultc["pd_colour"] !="") {
			echo " (";
			echo $lookupresultc["pd_colour"];				
			echo ')';
			}
			if ($lookupresultc["pd_stock"] <= 5) {
			echo '</td><td align="center" class="bodytext" style="border: 2px solid red;">';
			echo '<input name="stock[]" type="text" id="stock" value="';
                                echo $lookupresultc["pd_stock"];
                                echo '"style="width: 50px;" />'; 
			echo "</td></tr>";
			}else{
			echo '</td><td align="center" class="bodytext">';
			echo '<input name="stock[]" type="text" id="stock" value="';
                                echo $lookupresultc["pd_stock"];
                                echo '"style="width: 50px;" />'; 
			echo "</td></tr>";

			}



		} ?>
<tr>
                <td> </td>
                <td height="35"><a href="javascript: " onClick="javascript:document.forms.frmAmendStock.submit()" class="bodytext"><strong>click here to amend your stock </strong></a></td>
              </tr>
		</form> </table> 

 

And here is the code it should run on submission:

<?php
if (isset($_POST["submitted"])) {

for($i=0;$i<$_POST["count"];$i++){
mysql_query("UPDATE product SET pd_stock='$stock[$i]' WHERE pd_id='$id[$i]'");
}

}
?>

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.