UPDATE Mysql with PHP Variables
Posted: Mon Jul 21, 2008 2:42 pm
I'm a newbie to PHP and trying to UPDATE a Mysql db from a form on a PHP page. My code doesn't throw any errors, but as far as I can tell, nothing happens to the DB. Any thoughts on how to get this to work? Orders_id is the primary key for the zen_orders table and is autoincrement.
Code: Select all
<?php
if (!isset($_POST['submit'])) {
?>
<form action="" method="post">
Order ID: <input type="text" name="orders_id"><br />
Customer ID: <input type="text" name="customers_id"><br />
Customer Name: <input type="text" name="customers_name"><br />
Customer City: <input type="text" name="customers_city">
<input type="submit" name="submit" value="Submit!">
</form>
<?php
} else {
$orders_id = $_POST['orders_id'];
$customers_id = $_POST['customers_id'];
$customers_name = $_POST['customers_name'];
$customers_city = $_POST['customers_city'];
//MySQL string:
$sql = "UPDATE zen_orders SET
orders_id = '$orders_id',
customers_id = '$customers_id'
customers_name = '$customers_name'
WHERE orders_id='$orders_id'";
$result = mysql_query($sql);
//Output a result
if($result){
echo "Update Successful!";
} else {
$message = "Failed to update! This is the MySQL Error output:<br>" + mysql_error();}
}
?>