0

Hi all, i am having issues with my php and sql script. I have created a an update form that is populated with the database contents, however, when i edit the fields, the update script fails to update the database. The form looks like;

<form action="update-stock.php" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="text" value="<?php echo $make; ?>" maxlength="10" name="make" size="25" /><br />
<input type="text" value="<?php echo $model; ?>" maxlength="10" name="model" size="25" /><br />
<input type="text" value="<?php echo $price; ?>" maxlength="10" name="price" size="25" /><br />
<input type="text" value="<?php echo $engine; ?>" maxlength="10" name="engine" size="25" /><br />
<input type="text" value="<?php echo $gears; ?>" maxlength="10" name="gears" size="25" /><br />
<input type="text" value="<?php echo $tax; ?>" maxlength="10" name="tax" size="25" /><br />
<input type="text" value="<?php echo $year; ?>" maxlength="10" name="year" size="25" /><br />
<input type="text" value="<?php echo $fuel; ?>" maxlength="10" name="fuel" size="25" /><br />
<input type="text" value="<?php echo $miles; ?>" maxlength="10" name="miles" size="25" /><br />
<input type="text" value="<?php echo $transmission; ?>" maxlength="8" name="transmission" size="25" /><br />
<textarea cols="40" rows="5" name="description"><?php echo $description; ?></textarea><br />
<input type="submit" value="submit" />
</form>

My update-stock looks like;

<?php
if (isset($_POST['submit']))  {
				
$id=$_REQUEST['id'];
$make=$_REQUEST['make'];
$model=$_REQUEST['model'];
$price=$_REQUEST['price'];
$engine=$_REQUEST['engine'];
$gears=$_REQUEST['gears'];
$tax=$_REQUEST['tax'];
$year=$_REQUEST['year'];
$fuel=$_REQUEST['fuel'];
$miles=$_REQUEST['miles'];
$transmission=$_REQUEST['transmission'];
$description=$_REQUEST['description'];


				
$query= "UPDATE stock SET make='$make', model='$model', price='$price', engine='$engine', gears='$gears', tax='$tax', year='$year', fuel='$fuel', miles='$miles', transmission='$transmission', description='$description' WHERE id='$id";

mysql_query($query) or die(mysql_error());
mysql_close($db);
	
echo "<p>Congrats Record Updated</p>";
}
?>

I am certain the issue lies here as i am not getting anything returned.

3
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by kamran_FrizCon
0

Have you tried changing the $_REQUEST to $_POST? I am not sure if it would make a difference or not in this case, but it may not hurt to try...

0

Hi, thanks for the reply.

I have tried POST and GET and still nothing.

0

Just saw something. In your form, you have:

<input type="submit" value="submit" />

You haven't NAMED submit. You have a type and value, but no name. In the php, it is looking for a named variable "submit", which technically does not exist in "post" data. Try adding name="submit" and see what happens.

0

Ah ha, you are indeed right!

I am at least getting an error from the page now! i will get back to you with the result.

Thanks

0

Thanks so much, that fixed the issue.

The error message I was getting was due to a missing ' around the $id in the where statement.
:)

0

are u creating connection with database?

what error are u getting after little amendment in submit button, but i dint think is there is a problem with that.
i think errors are undefined variables that u didn't handle the null values for these variables.

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.