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
https://forums.phpfreaks.com/topic/236350-how-to-update-values-in-a-database/
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

Archived

This topic is now archived and is closed to further replies.

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