PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fionaom87
Forum Commoner
Posts: 43 Joined: Mon Feb 02, 2009 10:44 am
Post
by fionaom87 » 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.
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>
mbdigital
Forum Newbie
Posts: 21 Joined: Tue Feb 10, 2009 7:32 am
Location: NorthWest, England
Post
by mbdigital » Wed Feb 11, 2009 2:05 pm
Hi,
Are you able to input data into the database to begin with? i.e. is it updating or inserting new entries you're having the trouble with?
I would suggest starting by echoing the sql string to establish just what you're asking the mysql to do. from the looks of your string it might not be picking the php variables correctly.
fionaom87
Forum Commoner
Posts: 43 Joined: Mon Feb 02, 2009 10:44 am
Post
by fionaom87 » Wed Feb 11, 2009 2:15 pm
yes i am able to insert and select from my db, I have only started to learn php and mysql in the last month. Could you elaborate about php variables?
Thansk
F.
fionaom87
Forum Commoner
Posts: 43 Joined: Mon Feb 02, 2009 10:44 am
Post
by fionaom87 » Wed Feb 11, 2009 2:19 pm
I tried the echo function.following appears in Update1.php
HELLO
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\update1.php on line 10
HELLO
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\update1.php on line 18
Code: Select all
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php include 'config.php'; ?>
<?php
echo "HELLO"
?>
<?php
$sqlstr = mysql_query("SELECT * FROM customers WHERE customerid = '.$id;");
$amount_of_rows = mysql_num_rows($sqlstr); ?>
<?php
echo "HELLO"
?>
<?php
if ($amount_of_rows > 0);
{
while ($row = mysql_fetch_array($sqlstr)) {
?>
<?php
echo "HELLO"
?>
mbdigital
Forum Newbie
Posts: 21 Joined: Tue Feb 10, 2009 7:32 am
Location: NorthWest, England
Post
by mbdigital » Wed Feb 11, 2009 3:15 pm
I would try removing the semi colon from the end of your if statement. Also use the echo comman to echo the mysql query. I.e. echo $sqlstr;
This should give you a clear idea of what you're trying to tell the database to do.
watson516
Forum Contributor
Posts: 198 Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario
Post
by watson516 » Wed Feb 11, 2009 3:25 pm
Code: Select all
$sqlstr = mysql_query("SELECT * FROM customers WHERE customerid = '.$id;");
That line is messed up.
try something like
Code: Select all
$sqlstr = mysql_query("SELECT * FROM customers WHERE customerid = $id");
Your errors are telling you that your sql statement is wrong.
edit
You can't mix " and '
If you are concatenating a string and a variable, you dont need that extra " at the end
A ; is used at the end of statements only
fionaom87
Forum Commoner
Posts: 43 Joined: Mon Feb 02, 2009 10:44 am
Post
by fionaom87 » Wed Feb 11, 2009 3:35 pm
I am now getting this error
Parse error: parse error in C:\wamp\www\update1.php on line 67
Code: Select all
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php include 'config.php'; ?>
<?php
echo "HELLO"
?>
<?php
$sqlstr = mysql_query("SELECT * FROM customers WHERE customerid = '.$customerid;");
$amount_of_rows = mysql_num_rows($sqlstr); ?>
<?php
echo "HELLO"
?>
<?php
if ($amount_of_rows > 0)
{
while ($row = mysql_fetch_array($sqlstr)) {
?>
<?php
echo "HELLO"
?>
<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>
<td><input type="submit" value="Submit"></td>
</body>
</html>