0

I'm trying to create a form that updates stock in mysql database. I have created the forms to upload new stcok and they work fine. However, i'm including a link that will take the user to an update php that will then update the required fields, but i can't seem to get the databse to update, any help or indication where i'm going wrong?

This is the update form page;

<h1>Product Details</h1>
						
							<?php
							$product_id=$_GET['productID'];

							$query = "select * from bike_products where product_id = $product_id";
							$result = mysql_query($query);
							
							$row = mysql_fetch_array($result, MYSQL_ASSOC);
							echo "Product ID: $row[product_id]"."<br/>";
							echo "Product Number: $row[product_number]"."<br/>";
							echo "Product Name: $row[product_name]"."<br/>";
							echo "Product Price: $row[product_price]"."<br/>";
							echo "Product Description: $row[product_description]"."<br/>";
							echo "Last Updated: $row[update_timestamp]"."<br/>";		
		?>
		
		<div class="form">
	<form action= "<?php echo $_SERVER['process-edit-product.php']; ?>" method="post" enctype="multipart/form-data">
    <p>
			<label for="product_id">Product ID:</label><br/>
			<input type="text" name="product_id" id="product_id" size="50" maxlength="50" />
		</p>
		<p>
			<label for="product_number">Product Number:</label><br/>
			<input type="text" name="product_number" id="product_number" size="50" maxlength="50" />
		</p>
	  <p>
			<label for="product_name">Product Name:</label><br/>
			<input type="text" name="product_name" id="product_name" size="50" maxlength="50" />
		</p>
		<p>
			<label for="product_price">Price:</label><br/>
			<input type="text" name="product_price" id="product_price" size="50" maxlength="50" />
		</p>
		<p>
			<label for="product_description">Description:</label><br/>
			<input type="text" name="product_description" id="product_description" size="50" maxlength="50" />
		</p>
		<p><input type="submit" name="submit" value="Submit"/></p>
</form>			
</div>

This is the code that runs the submit;

<?php
require_once('connect.php');

if (isset($_POST['submit'])){

	//update products
	  if (!empty($_POST['product_id'])){
		$product_id = $_POST['product_id'];
		}
		if (!empty($_POST['product_number'])){
		$product_number = $_POST['product_number'];
		}
		if (!empty($_POST['product_name'])){
		$product_name = $_POST['product_name'];
		}
		if (!empty($_POST['product_price'])){
		$product_price = $_POST['product_price'];
		}
		if (!empty($_POST['product_description'])){
		$product_description = $_POST['product_description'];
		}
		$query = "update bike_products
							set product_number = $product_number,
							set product_name = $product_name,
							set product_price = $product_price,
							set product_description = $product_description
							where product_id = $product_id";
		
		mysql_query($query);
		}

	?>

Edited by digital-ether: Please use [code] tags to surround your code

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by diafol
0

Managed to sort it, i used the hidden attribute for input type and posted the ID. Worked a treat!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.