WHOA! WHOA! WHOA! Just stop right there big dog. Your taking the long way around things. Check this out.
<html>
<head>
<title> Customer Details </title>
</head>
<body>
<?php
if (isset($POST['addcustomer']))
{
$db = mysql_connect("localhost","root","");
mysql_select_db("customerdetails",$db);
$FirstName = $POST['FirstName'];
$LastName = $_POST['LastName'];
$sql = "INSERT INTO customerdetails VALUES(NULL,'$FirstName','$LastName')";
if(!(mysql_query($sql))) {
print("Could not exec query (".$sql."), MySQL reports: ".mysql_error());
exit();
}ELSE{
echo "<b> See PHP is really that easy! OH! Your details were also added.</b>";
}
}
?>
<form action=<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Please enter your details <br>
FirstName: <input type="text" name="FirstName"> <br>
LastName: <input type="text" name="LastName"> <br>
<input type="submit" name="submitcustomer" value="SUBMIT">
</p>
</form>
</body>
</html>
I changed a lot of things! Let me try and recap all the errors:
1.) if (isset($_GET['addcustomer'])): <-- You are using POST! NOT GET!
2.) $sql = "INSERT INTO customerdetails SET
CustomerID='$customerid"; <-- What the hell are you trying to use an Update statement mixed with an INSERT statement. Not going to work.
3.) LastName: <input type="text" name="LastName" /> <-- What is with the />?? Your not inside of the PHP block. You don't need to ignore that character. Just makes no sense.
4.) if (! @mysql_select_db('customerdetails' ) ) {
die ( '<p>Sorry Fernbarrrow website is experiencing difficuties at current.</p>');
} <-- WTF? Define the database you want to use and then check connection. This just looks sloppy!
5.) <?php
if (isset($_GET['addcustomer'])):
?> <-- Don't define that all the way up at the top with PHP at the bottom. Just leaves a lot of confusion. Makes the server work harder to figure that out as well. If you want your form to always appear just put it in a .inc. Makes life easier.
Hey just keep working and it just takes time and practice! If you need any help PLEASE don't hesistate to contact me! I am always willing to help! Check out www.ohhbad.com and you will find my E-Mail on there. Lata
Chad