madanthrax
IS-IT--Management
I am changing over to PHP/MySQL/Apache from ASP. I am just going through all the stuff in basic form that I will need for my first PHP app and have already wasted an incredible amount of time on an insert to DB page. I feel really stupid, but I just can't find the right combination for the if statement. The script below at least loads (I know it cant be right) but when the form submit button reloads the page the_POST[action] data is not activating the insert code. Any changes I make to the syntax result in a blank page. The insert code on its own works fine.
Your help can speed me on my way to freedom from MS.....
Anthony.
Your help can speed me on my way to freedom from MS.....
Code:
<?php virtual('/connections/PHPvirtual.php'); ?>
<?php
if ('$_POST[action]' == "insert")
{
mysql_select_db($database_PHPvirtual) or die( "Unable to find database");
$sql = "INSERT INTO Users (FirstName, LastName, Email) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[email]')";
mysql_query($sql);
mysql_close();
}
else
{
echo "Post info not found<br />";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Basic insert to db</title>
</head>
<body>
INSERT Record<br />
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" /><br />
Lastname: <input type="text" name="lastname" /><br />
Email: <input type="text" name="email" /><br />
<input name="action" type="hidden" value="insert" />
<input type="submit" value="Enter"/>
</form>
</body>
</html>
Anthony.
[sub]"Nothing is impossible until proven otherwise"[/sub]