Good Afternoon,
I am looking to create a page where I can enter data into a form and use INSERT to enter into the database. In the code example below, I have shown only 3 fields, but my page will have 13 fields and I want to designate 8 of them as "required"....meaning that you CANNOT hit Submit until those 8 fields are completed. What's happening now is you can enter a few and if you hit enter by mistake, I am getting partial db entries. any help would be appreciated. my code is below.
<center>
<font face="arial" size="5" color="ffffff"><b>Create a New Listing</b>
</center>
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<center><table width="600" border="1" cellspacing="0" cellpadding="1" bgcolor="ffffff">
<tr>
<td width="100" align="center" bgcolor="000000"><font face="arial" size="2" color="ffffff"><b>Field</b></td>
<td width="100" align="center" bgcolor="000000"><font face="arial" size="2" color="ffffff"><b>Format</b></td>
<td width="400" align="center" bgcolor="000000"><font face="arial" size="2" color="ffffff"><b>Values</b></td>
</tr>
<tr><td width="100" bgcolor="FFFFFF" align="center"><font face="arial" size="2" color="000000">MLS#</td>
<td width="100" bgcolor="CCCCCC" align="center"><font face="arial" size="1" color="000000">A1234</td>
<td width="400" bgcolor="CCCCCC" align="left"><font face="arial" size="2" color="000000">
<input type="text" align="left" size="10" name="MLS"></td></tr>
<tr><td width="100" bgcolor="FFFFFF" align="center"><font face="arial" size="2" color="000000">Price</td>
<td width="100" bgcolor="CCCCCC" align="center"><font face="arial" size="1" color="000000">150000</td>
<td width="400" bgcolor="CCCCCC" align="left"><font face="arial" size="2" color="000000">
<input type="text" align="left" size="10" name="Price"></td></tr>
<tr><td width="100" bgcolor="FFFFFF" align="center"><font face="arial" size="2" color="000000">Address</td>
<td width="100" bgcolor="CCCCCC" align="center"><font face="arial" size="1" color="000000">1234 Fatima</td>
<td width="400" bgcolor="CCCCCC" align="left"><font face="arial" size="2" color="000000">
<input type="text" align="left" size="60" name="Address"></td></tr>
</table>
<input type="submit" name="Submit" value="Submit">
</form>
<?php
$connect = mysql_connect("localhost", "****", "*****") or die(mysql_error());
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("gunndb", $connect);
$insert="INSERT INTO listings (MLS, Price, Address)
VALUES
('$_POST[MLS]','$_POST[Price]','$_POST[Address]')";
if (!mysql_query($insert,$connect))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
echo "<table width='500' border='1' cellspacing='0' cellpadding='1' bgcolor='ffffff'>";
echo "<tr>
<td width='100' align='center' bgcolor='000000'><font face='arial' size='2' color='ffffff'><b>Field</b></td>
<td width='400' align='center' bgcolor='000000'><font face='arial' size='2' color='ffffff'><b>Value</b></td>
</tr>";
echo "<tr>
<td width='100' align='center' bgcolor='ffffff'><font face='arial' size='2' color='000000'><b>MLS#</b></td>
<td width='400' align='center' bgcolor='ffffff'><font face='arial' size='2' color='000000'><b>$_POST[MLS]</b></td>
</tr>";
echo "<tr>
<td width='100' align='center' bgcolor='ffffff'><font face='arial' size='2' color='000000'><b>Price</b></td>
<td width='400' align='center' bgcolor='ffffff'><font face='arial' size='2' color='000000'><b>$_POST[Price]</b></td>
</tr>";
echo "<tr>
<td width='100' align='center' bgcolor='ffffff'><font face='arial' size='2' color='000000'><b>Address</b></td>
<td width='400' align='center' bgcolor='ffffff'><font face='arial' size='2' color='000000'><b>$_POST[Address]</b></td>
</tr>";
echo "</table>";
mysql_close($connect)
?>