Jump to content

how to update values in a database


lanceox

Recommended Posts

Hi guys, i have a select box which has been populated with values from the database however i would like to be able to select the value from the select box and change the qty. 

 

<!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>stock manager</title>
</head>

<body>
<?php

$stockqty =&$_POST['stock_qty1'];
?>
<center>
<table>
<td>
    	<table>
<td>
        <form action='stockview.php' method='POST'>
        Please Enter a Stock Name and Stock Value
        
        <table>
            <tr>
            <td>
                Stock Name:
            </td>
            <td>
              <input name="stock_name" type="text" /><BR />
            </td>
        </tr>
        <tr>
            <td>
                Stock Qty:
            </td>
            <td>
                <input name="stock_qty" type="text" />
            </td>
        </tr>
        
        </table>
         <input name="submit" type="submit" value="Add New Stock Items" />
        </form>
  	</td>
</table>
</td>

<td>
    
<table>
<td>
	<form action='stockmanager.php' method='POST' enctype="multipart/form-data">
       	Please Select from the list the item you wish to update
          <table>
            <tr>
            	<td>
               		 Stock Name:
            	</td>
           		 <td>
                
                <?php	
			$connect = mysql_connect("localhost","root", "") or die ("Couldn't Connect!");
			mysql_select_db("stock", $connect) or die("Couldn't find db"); // select database

			$query=("SELECT id, stockname FROM stocks");
			$result = mysql_query ($query);
			echo "<select name=stock value=''>Edit Stock QTY</option>";

			while($nt=mysql_fetch_array($result))
			{	//Array or records stored in $nt
				echo "<option value=$nt[id]>$nt[stockname]</option>";
				/* Option values are added by looping through the array */
			}


			$queryreg = mysql_query("SELECT * FROM stocks WHERE stockqty='$stockqty'");
			$numrows = mysql_num_rows($queryreg);

			$update = mysql_query("UPDATE stocks SET stockqty='$stockqty' WHERE stockname  = '$stockname'");
			echo("Its updated");
			?>
                
                
            </td>
        	</tr>
        	<tr>
            	<td>
               	 Stock Qty:
            	</td>
            	<td>
                	<input name="stock_qty1" type="text" />
            	</td>
        	</tr>
        </table>
         <input name="submit" type="submit" value="Update stock items" />
        </form>
   	 </td>
</table>
</td>
</table>

</center>


</body>
</html>

 

Any help would be greatly appreciated... ive been working on this for a while and cant seem to find the answer.

 

Thanks

 

Lance

Link to comment
Share on other sites

Everything works fine and the select box appears and i can choose options from the database, however when i enter a new quantity the values are not modified....  So is there something wrong with the actual insert statements

 

Im not sure how to choose the value from the select field.

 

Hope this makes more sense :)

 

Thanks

 

Lance

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.