Forum Moderators: coopster

Message Too Old, No Replies

Updating not successful. but says it is

Trying to update.. but not succeeding

         

JSoaper

2:36 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



I am trying without success to update my database using the following script. It says successful but is not. Any help greatly appreciated.

<?php

//LAST UPDATE
// 27-09-2007

include("config.php");

$id = $_GET['id'];

if(isset($_POST['submit']))
{

$Account = $_POST['Account'];
$Client = $_POST['Client'];
$Telephone = $_POST['Telephone'];
$Type= $_POST["Type"];
$Address = $_POST["Address"];
$Address1= $_POST["Address1"];
$Suburb= $_POST["Suburb"];
$PostalC= $_POST["PostalC"];
$Postal= $_POST["Postal"];
$Postal1 = $_POST["Postal1"];
$PostalC1 = $_POST["PostalC1"];

$result = mysql_query("UPDATE clients SET Account='$Account', Client='$Client', Telephone='$Telephone', Type='$Type',
Address='$Address', Address1='$Address1', Suburb='$Suburb', PostalC='$PostalC', Postal='$Postal', Postal1='$Postal1',
PostalC1='$PostalC1',Fax='$Fax' WHERE id='$id' ",$connect);

echo "<b>Thank you! The Clients details have been updated successfully!<br>You will now be redirected to the Home Page";
echo "<meta http-equiv=Refresh content=3;url=lookup.php>";
}
elseif($id)
{

$result = mysql_query("SELECT * FROM clients WHERE id='$id' ",$connect);
while($myrow = mysql_fetch_assoc($result))
{
$Account = $myrow["Account"];
$Client = $myrow["Client"];
$Type= $myrow["Type"];
$Address = $myrow["Address"];
$Address1= $myrow["Address1"];
$Suburb= $myrow["Suburb"];
$PostalC= $myrow["PostalC"];
$Postal= $myrow["Postal"];
$Postal1 = $myrow["Postal1"];
$PostalC1 = $myrow["PostalC1"];
$Telephone= $myrow["Telephone"];
$Fax= $myrow["Fax"];
?>
<link href="pman.css" rel="stylesheet" type="text/css">

<b>Update Clients</b>

<form method="post" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="id" value="<? echo $myrow['id']?>">
<table border="0" width="760" cellpadding="0" cellspacing="0" >
<tr>
<td bgcolor="#000000" colspan="2">

<div align="center">

<table border="0" width="100%" cellspacing="0" >
<tr>
<td>

<font color="#FF0000"><b>Client Listings </b></font>
</td>
<td><input type="text" name="Type" size="12" value="<? echo $Type; ?>"></td>
</tr>
</table>
</div>
</td>
<td bgcolor="#000000" colspan="2">

<p align="right">

<input name="User" size=20 style="float: right" value="<? echo $User; ?>"><font color="#FFFFFF">
<b>Last Updated:</b></td>
</tr>
<tr>
<td width="84" bgcolor="#C0C0C0">

<b>Company</b><b>:</b></td>
<td width="512" colspan="2">

<input type="text" readonly name="Client" size="40" value="<? echo $Client; ?>">
<input type="text" name="Account" value="<? echo $Account; ?>" size="10">

</td>
<td width="166">
<p align="center"></td>
</tr>
<tr>
<td width="85" bgcolor="#C0C0C0">

<b>Address:</b> </td>
<td colspan="3">


<input type="text" name="Address" size="30" value="<? echo $Address; ?>">
<input type="text" name="Address1" size="20" value="<? echo $Address1; ?>">
<input type="text" name="Suburb" size="20" value="<? echo $Suburb; ?>">
<input type="text" name="PostalC" size="8" value="<? echo $PostalC; ?>"></td>
</tr>
<tr>
<td width="84" bgcolor="#C0C0C0">

<b>Postal</b><font face="Verdana" size="1"><b>:</b>

</td>
<td width="760" colspan="3">


<input type="text" name="Postal" size="30" value="<? echo $Postal; ?>">
<input type="text" name="Postal1" size="20" value="<? echo $Postal1; ?>">
<input type="text" name="PostalC1" size="8" value="<? echo $PostalC1; ?>"></td>
</tr>
<tr>
<td width="84" bgcolor="#C0C0C0">

<b>Telephone</b><font face="Verdana" size="1"><b>:</b></td>
<td width="409">


<input type="text" name="Telephone" size="25" value="<? echo $Telephone; ?>"></td>
<td width="41" bgcolor="#C0C0C0">
<p align="right">

<b>Fax:</b></td>
<td width="166">


<input type="text" name="Fax" size="23" value="<? echo $Fax; ?>"></td>
</tr>
<tr>
<td bgcolor="#000000" colspan="4" height="4">
</td>
</tr>
<tr>
<td width="760" valign="top" colspan="4">

<div align="center">

<table border="0" width="760" cellpadding="0" cellspacing="0">
<font face="Verdana" size="3">
<tr>

<td bgcolor="#000000" height="4"></td>
</tr>

<tr>
<td>
&nbsp;</td>
</tr>
</table>
</div>

<div align="center">
</div>
</td>
</tr>
<tr>
<td colspan="4">
<p align="center">
<b>
<input type="submit" name="submit" value="Update Record">
<input type=button value="[ Cancel ]" onclick="history.back()"></td>
</tr>

</table></form>
<?
}//end of while loop

}//end else
?>

[edited by: JSoaper at 2:50 pm (utc) on Feb. 10, 2009]

tbarbedo

4:15 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



The reason why it is echoing out successful is because you are not checking if $result went through, you are simply outputting successful no matter what happens...

You need to do the following to figure out what is wrong...

if ($result){ //If the query goes through
echo "<b>Thank you! The Clients details have been updated successfully!<br>You will now be redirected to the Home Page";

} else { //If there is an error with the query exit and show the error
exit(mysql_error());
}

Your record is probably not updating because of a problem in your query....

make sure when you use $_POST variables to update a table you escape certain characters...for example..

$Account = mysql_escape_string($_POST["Account"]);

whoisgregg

7:18 pm on Feb 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When escaping data for MySQL, make sure you use the current escape function, mysql_real_escape_string() [php.net].

The old version "mysql_escape_string" is deprecated and should no longer be used.