By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,967 Members | 815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,967 IT Pros & Developers. It's quick & easy.

Unable to update and delete

P: 1
[PHP]
<?
session_start();

require("db.php");

mysql_connect(MACHINE, USER, '');
mysql_select_db(DBNAME);

$username = $_SESSION['username'];
$pwd =$_SESSION['pwd'];

if(isset($username)){

$customerid = $_POST['customerid'];
$customername = $_POST['customername'];
$customercontact = $_POST['customercontact'];
$orderid = $_POST['orderid'];

$sql = "SELECT * FROM customer";

$result = mysql_query($sql) or die("Unable to get order info");

$row = mysql_fetch_assoc($result);
extract($row);

}
?>

<html>
<head>
<title>Update Customer Details</title>
</head>
<body>
<form action="do_updatecustomer.php?action=do_updatecust omer&orderid=<?php echo $orderid; ?>" enctype="multipart/form-data" method='post'><br>
<link rel="stylesheet" type="text/css" href="fyp.css" />
<b></b><br><br>
<table border="0">

<tr><td>Customer Name:</td>
<td><input type="text" name ="customername" value ="<?php echo $customername; ?>"></td></tr>

<tr><td>Customer Contact:</td>
<td><input type="text" name ="customercontact" value ="<?php echo $customercontact; ?>"></td></tr>

<tr><td>Order ID:</td>
<td><input type="text" name ="orderid" value ="<?php echo $orderid; ?>"></td></tr>

<tr><td><input type="reset" value="Reset"></td>
<td><input type = "Submit" name="submit" value="Update"></td></tr>

</table>
</form>
</body>
</html>


<?

session_start();

require("db.php");

mysql_connect(MACHINE, USER, '');
mysql_select_db(DBNAME);

if (isset($_POST['submit']))
{
$customerid = $_GET['customerid'];
$customername = $_POST['customername'];
$customercontact = $_POST['customercontact'];
$orderid = $_POST['orderid'];


$sql = "UPDATE 'customer' SET 'customername' = '$customername',
'customercontact' = '$customercontact','orderid' = '$orderid' WHERE 'customerid' = '$customerid'";

$result = mysql_query($sql) or die ("Unable to Update Customer Information");
}


//echo "Customer Details has been updated from database.";


//<br><br>
//"<a href=cus_details.php>View Customer Details</a><br>";
//"<a href=index.php>Go to Mainpage</a><br>";
?>
[/PHP]

I can't seem to update...Could someone be so kind to help me check my codes =)
Jul 8 '07 #1
Share this Question
Share on Google+
2 Replies


mwasif
Expert 100+
P: 801
Can you explain "it cant seem to update"?

Use this query to update
Expand|Select|Wrap|Line Numbers
  1. $sql = "UPDATE customer SET customername = '$customername',
  2.         customercontact = '$customercontact', orderid = '$orderid' WHERE customerid = '$customerid'";
You were using single quotes instead of back tick (`) around table name and column.
Jul 8 '07 #2

mwasif
Expert 100+
P: 801
Also replace your update query line to this

[PHP]$result = mysql_query($sql) or die ("Unable to Update Customer Information. Error: ".mysql_error());[/PHP]

mysql_error() will return the sql error.
Jul 8 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.