Updating mysql database.
Posted: Wed Feb 11, 2009 1:21 pm
Hello, i am trying to update my database but doesnt seem to be working.i want to be able to insert a specific customer id, update its info.
Thanks
F.
Thanks
F.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>Update</title>
</head>
<body bgcolor="white">
<form method="POST" action="update1.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="blue">Customer ID:</font></td>
<td><input type="text" name="customerid" size=10></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
Code: Select all
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php include 'config.php'; ?>
<?php
$sqlstr = mysql_query("SELECT * FROM customers WHERE customerid = '.$id;");
$amount_of_rows = mysql_num_rows($sqlstr); ?>
<?php
if ($amount_of_rows > 0);
{
while ($row = mysql_fetch_array($sqlstr)) {
?>
<html>
<head>
<title>Update</title>
</head>
<body bgcolor="white">
<form method="post" action="update2.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="blue">Customer Name:</font></td>
<td><input type="text" name="name"
value="<?php echo $row["name"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Customer Address:</font></td>
<td><input type="text" name="address"
value="<?php echo $row["address"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Telephone number:</font></td>
<td><input type="text" name="telephoneno"
value="<?php echo $row["telephoneno"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">House Type:</font></td>
<td><input type="text" name="housetype"
value="<?php echo $row["housetype"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Date:</font></td>
<td><input type="text" name="date"
value="<?php echo $row["date"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Customer ID:</font></td>
<td><input type="text" name="customerid"
value="<?php echo $row["customerid"]; ?>" size=100></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
<?php
}
}
?>
</body>
</html>
Code: Select all
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<html>
<head>
<title>Update 2</title>
</head>
<body bgcolor="white">
<?php include 'config.php'; ?>
<?php
$name=$_POST['name'];
$address=$_POST['address'];
$telephoneno=$_POST['telephoneno'];
$housetype=$_POST['housetype'];
$phone=$_POST['phone'];
$customerid=$_POST['customerid'];
$query="UPDATE customers SET name ='$name', address='$address', telephoneno='$telephoneno', housetype ='$housetype', phone ='$phone' WHERE customerid ='$customerid' ";
mysql_query($query);
mysql_close($con);
?>
</body>
</html>