Forum Moderators: coopster
Can someone please help.....
<form action="<?php echo ''.$_SERVER['PHP_SELF'].'';?>" method="post">
<table width="95%" border="0">
<tr>
<td width="14%"> </td>
<td width="27%">First Name: </td>
<td width="37%"><input type="text" name="first"></td>
<td width="22%"> </td>
</tr>
<tr>
<td> </td>
<td>Last Name: </td>
<td><input type="text" name="last"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Phone: </td>
<td><input type="text" name="phone"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Mobile: </td>
<td><input type="text" name="mobile"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Fax: </td>
<td><input type="text" name="fax"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input name="Submit" type="Submit"></td>
<td> </td>
</tr>
</table>
</form>
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax')";
mysql_query($query);
echo "Record $first Inserted";
mysql_close();
?>
<p><br>
<a href="insert.php">insert another</a></p>
<p><br>
<a href="index.php">view table</a></p>
Thanks for taking time to look at my code, have tried inserting the code you offered as below:
</form>
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if (isset($_POST['Submit']))
{
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$...')";
mysql_query($query);
echo "Record $first Inserted";
}
else {
echo "Insert a file";
}
mysql_close();
?>
I can see the else statement on the page, which is good, as it confirms not insert has been done, but when entering details and clicking submit, there is no action on db.
Thanks in adv
I recommend using the so called superglobal variables $_POST, $_GET et cetera, as you may one day find yourself on a server with register_globals set to off. In that case you can't simply call $first, $last anymore. More on that topic in the manual [nl2.php.net].