I am very new to PHP and have a problem I am trying to write a repair db such that users can input the information about the item they are sending to us so we know it is coming and ultimately I want to use the pages to be a resource so users can track progress.
The problem I have is with the processing page, the db - repairusers has fields to match each of the input fields from the form plus an id column which is auto-incrementing and ultimately becomes the reference number for the repair. I can get the script to return the users name but I cannot get it to feed back the id (ref no.) it either displays nothing or it displays all the numbers in the id column. Ultimately I would like to be able have it display all the data from the last entered record so that the user can print it out!
The main page is repair.html which is as follows:
<!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>Repair Form</title>
<style type="text/css">
<!--
.style2 {font-size: x-large}
.style3 {
font-size: x-large;
color: #326598;
font-weight: bold;
}
-->
</style>
</head>
<body>
<!-------------begin form------------>
<FORM ACTION="formindb.php" METHOD="POST" NAME="contact_form">
<p><img src="images/logo1.shop.300x64.gif" alt="Logo" width="300" height="64" /></p>
<TABLE width="481" align="center">
<TR>
<TD colspan="3"><div align="center" class="style3">Customer Details</div></TD>
</TR>
<TR>
<TD width="103"><div align="right">Name:</div></TD>
<TD width="11"> </TD>
<TD width="351"><input name="name" type="text" size="50" /></TD>
</TR>
<TR>
<td><div align="right">Address 1:</div></td>
<td> </td>
<TD> <input name="address1" type="text" size="50" /> </TD>
</TR>
<TR>
<td><div align="right">Address 2:</div></td>
<td> </td>
<TD><input name="address2" type="text" size="50" /></TD>
</TR>
<TR>
<td><div align="right">Town/City:</div></td>
<td> </td>
<TD><input name="town" type="text" size="50" /></TD>
</TR>
<TR>
<td><div align="right">Postcode:</div></td>
<td> </td>
<TD> <input name="postcode" type="text" size="50" /></TD>
</TR>
<TR>
<td><div align="right">Phone:</div></td>
<td> </td>
<TD><input name="phone" type="text" size="50" /></TD>
</TR>
<TR>
<TD><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email Address:</font></div></TD>
<TD> </TD>
<TD><input name="email" type="text" size="50" /></TD>
</TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>
</TABLE>
<table width="733" height="331" border="0" align="center">
<tr>
<td height="43" colspan="3"><div align="center"><span class="style3">Product Details</span></div></td>
</tr>
<tr>
<td width="103" align="center" valign="middle"><div align="right">Make: </div>
</label></td>
<td width="14"> </td>
<td width="602"><input name="Make" type="text" size="50" /></td>
</tr>
<tr>
<td><div align="right">Model:</div></td>
<td> </td>
<td><input name="Model" type="text" size="50" maxlength="30" /></td>
</tr>
<tr>
<td><div align="right">Serial No:</div></td>
<td> </td>
<td><label>
<input name="Serial" type="text" size="50" />
</label></td>
</tr>
<tr>
<td valign="top"><div align="right">Comments:</div></td>
<td> </td>
<td><label>
<textarea name="Comments" cols="80" rows="8" ></textarea>
</label></td>
</tr>
<tr>
<td><div align="right">Included Accesories:</div></td>
<td> </td>
<td><label>
<input name="Accesories" type="text" size="100" />
</label></td>
</tr>
</table>
<table width="733" height="314" border="0" align="center">
<tr>
<td height="36" align="center" class="style2"><div align="center" class="style3">Brief description of fault:</div></td>
</tr>
<tr>
<td height="270" align="center" valign="top"><label>
<div align="center">
<textarea name="Fault" cols="100" rows="15"></textarea>
</div>
</label></td>
</tr>
</table>
<div align="center"></div>
<p align="center">
<input type="submit" value="Submit" name="Submit" />
<img src="../images/spacer.gif" width="1" height="1" />
<img src="../images/spacer.gif" width="1" height="1" />
<input type="reset" value="Reset" name="Reset" />
</p>
</FORM>
<!-------------end form------------>
</body>
</html>
the processing script formindb.php is as follows:-
<!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">
<body>
<?php
$con = mysql_connect("localhost","dbname","dbpassword"); //Replace with your actual MySQL DB Username and Password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db249159135", $con); //Replace with your MySQL DB Name
$id=mysql_real_escape_string($_POST['id']); //This value has to be the same as in the HTML form file
$name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file
$address1=mysql_real_escape_string($_POST['address1']); //This value has to be the same as in the HTML form file
$address2=mysql_real_escape_string($_POST['address2']); //This value has to be the same as in the HTML form file
$town=mysql_real_escape_string($_POST['town']); //This value has to be the same as in the HTML form file
$postcode=mysql_real_escape_string($_POST['postcode']); //This value has to be the same as in the HTML form file
$phone=mysql_real_escape_string($_POST['phone']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file
$Make=mysql_real_escape_string($_POST['Make']); //This value has to be the same as in the HTML form file
$Model=mysql_real_escape_string($_POST['Model']); //This value has to be the same as in the HTML form file
$Serial=mysql_real_escape_string($_POST['Serial']); //This value has to be the same as in the HTML form file
$Comments=mysql_real_escape_string($_POST['Comments']); //This value has to be the same as in the HTML form file
$Accesories=mysql_real_escape_string($_POST['Accesories']); //This value has to be the same as in the HTML form file
$Fault=mysql_real_escape_string($_POST['Fault']); //This value has to be the same as in the HTML form file
$sql="INSERT INTO RepairUsers (name,address1,address2,town,postcode,phone,email,Make,Model,Serial,Comments,Accesories,Fault) VALUES ('$name','$address1','$address2','$town','$postcode','$phone','$email','$Make','$Model','$Serial','$Comments','$Accesories','$Fault')"; /*form_data is the name of the MySQL table where the
form data will be saved.
name, address1 etc. are the respective table fields*/
if (!mysql_query($sql,$con))
die('Error: ' . mysql_error());
echo "Thank you for completing your repair sheet {$name}<br />";
$sql = "SELECT * FROM RepairUsers";
$query = mysql_query($sql);
($row = mysql_fetch_array($query));
echo "Your reference number is {$row['id']}";
echo $row['name'];
mysql_close($con);
?>
</body>
</html>
Any advice for this novice would be much appreciated