newbie question on php and forms
I have the below code which is suppose to post back to itself but I can't get it to get the data from the form to be inserted into the database correctly and then get the data that was just inserted into the database and displayed it in a table.. I keep getting Query error. Can someone help me out?
PHP Code:
<?php
//Database Connection
$msdb = mysql_connect("localhost", "user", "pass");
$db = mysql_select_db("test", $msdb) or die(mysql_error());
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
if (!isset($_POST['send']))
{
?>
<html>
<title></title>
<head></head>
<body TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<form id = "maintenanceForm" Name = "maintenanceForm" action="<?=$_SERVER['PHP_SELF']?>" method="POST" >
<fieldset>
<input type="hidden" id ="send" name="send" value="true">
<table cellpadding="5" cellspacing="0" border="0" align="center">
<tr>
<td align="right" class="formLabel"><B>First Name</B>:</td>
<td align="left"><INPUT id ="fnamel" NAME="fname" VALUE=""><BR></td>
</tr>
<tr>
<td align="right" class="formLabel"><label for="name"><B>Last Name</B></label>:</td>
<td align="left"><INPUT id = "lname" NAME="lname" VALUE=""><BR>
</div></td>
</tr>
<tr>
<td align="right" class="formLabel"><B>Phone</B>:</td>
<td align="left"><INPUT id ="phone" NAME="phone" VALUE=""><BR>
</td>
<td align="right"> </td>
<td align="left"><INPUT TYPE='submit' id = "submit" NAME='submit' VALUE='Send'></td>
</tr>
</table>
</form>
<?php
}
else
{
$insertSql = "INSERT INTO members (firstname, lastname, phone) VALUES ('$fname', '$lname', '$phone')";
$result = mysql_query($insertSqL) or die("Insert Query failed: " . mysql_error());
$selectSQL = "SELECT FROM memebers where id = ". mysql_insert_id();
$result = mysql_query($selectSQL)
or die("Select Query failed: " . mysql_error());
echo "<TABLE BORDER='1'>";
echo "<TR>";
echo "<TH>First Name</TH><TH>Last Name</TH><TH>Phone</TH>";
echo "</TR>";
while ($row = mysql_fetch_array($result))
{
echo "<TR>";
echo "<TD>", $row['fname'], "</TD><TD>", $row['lname'], "</TD><TD>", $row['phone'], "</TD>";
echo "</TR>";
}
echo "</TABLE>";
mysql_close($connection);
}
?>
</body>
</html>