samedi 11 avril 2015

My UPDATE SQL is either not working or working differently than I need

So I am making a website and need to make it so the admin user can edit a product price using an input and submit form.


The PHP code I am using to edit this is as follows:



if (isset ($_GET['editPrice']))
{
$newID = $_GET['new_ID'];
$newprice = $_GET['new_price'];

$sqlEdit = "UPDATE products SET price = '.$newprice' WHERE product_ID = '.$newID'";

if ($conn->query($sqlEdit) === TRUE)
{
echo "Edited price successfully";
}
else
{
echo "Error: " . $sqlEdit . "<br>" .$conn->error;
}
}


where new_ID and new_price are both the names of the textboxes for my form:



<form action="adminPage.php" method="get">
Product ID to update:<input type="number" name="new_ID"><br>
New price:<input type="number" name="new_price"><br>

<input type="submit" name="editPrice">
</form>


however the product ID isn't registering, it's as if their is no value being input into the variable $newID because when I select ID 1 and the price of say 500 it doesn't change product ID 1, although when I change my SQL to a simple WHERE product_ID = 1"; it works.


My second issue is the fact that enter 500 doesn't set the price to 500, it sets it to 0.50, is there any way to correctly enter in a decimal price value from a form?





Aucun commentaire:

Enregistrer un commentaire