Member Avatar for jpknoob

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.

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

Member Avatar for jpknoob

Hi, thanks for the reply.

I have tried POST and GET and still nothing.

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.

Member Avatar for jpknoob

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

Glad to be of assistance. ;)

Please mark thread "Solved" if it fixes the problem. :)

Member Avatar for jpknoob

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.
:)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.