Script not updating database

admin

Administrator
Staff member
Hiya,

I've made this script to when you go to the page you can add a new record then it comes up with a check details page this all works fine, but on the check records part the data comes up in a form so you can edit the fields when you have made any changes it creates a new record and does not update the existing one could some one tell me why please?

Code is below thanks

Peter

<?

$db = mysql_connect("localhost","root","password");
mysql_select_db("rentdb",$db);

if ($submit){

$rs = mysql_query("INSERT INTO app (name,company,address,suburb,state,post,areacode,phone,faxareacode,fax,email) VALUES ('$name','$company','$address','suburb','$state','$post','$areacode','$phone','$faxareacode','$fax','$email')");

if($name){

$rs = mysql_query("UPDATE app SET name='$name',company='$company',address='$address',suburb='$suburb',state='$state',post='$post',areacode='$areacode',phone='$phone',faxareacode='$faxareacode',fax='$fax',email='$email' WHERE name=$name");

}

$result = mysql_query($rs);



echo "<p><p>";
echo "<TABLE BORDER=0 WIDTH=800 >";
echo "<tr><td>";


?>
<table border="0" width="650" align="center">
<tr>
<td>
<font face="Helvetica, sans-serif" size="3" color="#00499C"> Please Check your information, and change any details that are not correct, then click update.<br>
if this information is correct <a href=http://www.phpbuilder.com/board/archive/index.php/"thankyou.html">click here</a>.</font><p>
</td>
</tr>
</table>
<form name=check method="POST" action="">
<input type="hidden" name="name" value="<?=$name?>">
<?

echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=500 BGCOLOR=#990033 ALIGN=CENTER>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td colspan=2 bgcolor=#006699><div align=center>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF><b>The information you entered is:</b></font>\n";
echo "</div></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF><b>Your Name:</b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=name value='$name'></font></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFF><b>Company:</b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=company value='http://www.phpbuilder.com/board/archive/index.php/$company'></font></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF width=180><b>Address:<b></b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=address value='http://www.phpbuilder.com/board/archive/index.php/$address'></font></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF width=180><b>Suburb:<b></b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=suburb value='http://www.phpbuilder.com/board/archive/index.php/$suburb'></font></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF width=180><b>State:<b></b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=state value='http://www.phpbuilder.com/board/archive/index.php/$state'></font></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>";
echo "<td bgcolor=#006699 width=122>";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF width=180><b>Post Code:<b></b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=post value='http://www.phpbuilder.com/board/archive/index.php/$post'></font></td></tr>\n\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF width=180><b>Phone:*<b></b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=areacode SIZE=2 MAXLENGTH=2 value='http://www.phpbuilder.com/board/archive/index.php/$areacode'><input type=text name=phone value='http://www.phpbuilder.com/board/archive/index.php/$phone'></font></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF width=180><b>Fax:*<b></b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=faxareacode SIZE=2 MAXLENGTH=2 value='http://www.phpbuilder.com/board/archive/index.php/$faxareacode'><input type=text name=fax value='http://www.phpbuilder.com/board/archive/index.php/$fax'></font></td></tr>\n";
echo "<tr BGCOLOR=#CCCCCC>\n";
echo "<td bgcolor=#006699 width=122>\n";
echo "<font face=Helvetica, sans-serif size=3 color=#FFFFFF width=180><b>Email Address:<b></b></font></td>\n";
echo "<td><div align=center><font face=Helvetica, sans-serif size=3 color=#000000><input type=text name=email value='http://www.phpbuilder.com/board/archive/index.php/$email'></font></td></tr>\n";
echo "<tr><td colspan=2 bgcolor=#CCCCCC><div align=center><input type=submit name=submit value=http://www.phpbuilder.com/board/archive/index.php/update></div></td>\n</tr>\n</table>\n</form><p>\n";
?>
<font face="Helvetica, sans-serif" size="3" color="#00499C"><b>* Please Include your area code with your phone & fax number.</b></font>
<?
echo "</td></tr></table>\n";


} else {


?> <table width="800" border="0">
<tr>
<td height="485">
<form method="post" action="" name="app">
<!-- <input type="hidden" name="id" value="<?=$id?>"> -->
<blockquote>
<table width="700" border="0">
<tr>
<td width="64" height="2"><font face="Helvetica, sans-serif" size="3" color="#00499C">Name:</font></td><td width="626" height="2">
<input type="text" name="name">
</td>
</tr>
<tr>
<td width="64" height="2"><font face="Helvetica, sans-serif" size="3" color="#00499C">Company:</font></td>
<td width="626" height="2">
<input type="text" name="company">
</td>
</tr>
<tr> <td width="64" height="2"><font face="Helvetica, sans-serif" size="3" color="#00499C"> Address: </font></td>
<td width="626" height="2">
<input type="text" name="address" size="35"> <font face="Helvetica, sans-serif" size="3" color="#00499C"> Suburb: </font> <input type="text" name="suburb"><br> <font face="Helvetica, sans-serif" size="3" color="#00499C"> State: </font>
<select name="state" size="1">
<option value="Canberra">ACT</option>
<option value="New South Wales">NSW</option>
<option value="Northern Territory">NT</option> <option value="Queensland">QLD</option>
<option value="South Australia">SA</option>
<option value="Tasmania">TAS</option>
<option value="Victoria">VIC</option>
<option value="Western Australia">WA</option>
</select>
<font face="Helvetica, sans-serif" size="3" color="#00499C"> Post Code: <input type="text" name="post" size="4"> </td></tr>
<tr><td width="64" height="2"><font face="Helvetica, sans-serif" size="3" color="#00499C">Phone:*</td>
<td width="626" height="2">
<SELECT NAME="areacode">
<OPTION VALUE="02">02</OPTION>
<OPTION VALUE="03">03</OPTION>
<OPTION VALUE="07">07</OPTION>
<OPTION VALUE="08">08</OPTION>
</SELECT>
<input type="text" name="phone" size="10" maxlength="9">
</td></tr> <tr> <td width="64" height="2"><font face="Helvetica, sans-serif" size="3" color="#00499C">Fax:*</td><td width="626" height="2">
<SELECT NAME="faxareacode">
<OPTION VALUE="02">02</OPTION>
<OPTION VALUE="03">03</OPTION>
<OPTION VALUE="07">07</OPTION>
<OPTION VALUE="08">08</OPTION>
</SELECT>
<input type="text" name="fax"> </td></tr>
<tr> <td width="64" height="2"><font face="Helvetica, sans-serif" size="3" color="#00499C">Email:</td><td width="626" height="2">
<input type="text" name="email"> </td></tr> <tr>
<td width="64" height="2">&nbsp;</td><td width="626" height="2">
<input type="submit" name="submit" value="Submit"> <input type="reset" name="submit2" value="Clear">
<p>
<font face="Helvetica, sans-serif" size="3" color="#00499C"><b>* Please Include your area code with your phone & fax number.</b></font>
</td>
</tr>
</table>
</blockquote>
</form>
<?
}

?>
 
Back
Top