PHP Insert Data Form
| From: | Edson Waite | Date: | Thu, 02 Jan 2003 04:35:32 +0000 |
| Subject: | PHP Insert Data Form | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-129915@lists.php.net to get a copy of this message | ||
Hi All,
Hope everyone had a safe and happy New Year, I am still having trouble
getting an insert data form to work. Below is the code. I was also wondering
if anyone could tell me the PHP Configuration settings necessary to allow a
form to insert data into a MySQL database.
To view this page, http://www.airforcemuseum.com/newentry.htm
<html>
<head>
<title>Test Form Entry Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Entry Results</h1>
<?
if (!$firstName || !$lastName)
{
echo "You have not entered the required details.<br>"
."Please go back and try again.";
exit;
}
$firstName = addslashes($firstName);
$lastName = addslashes($lastName);
$dbcnx = @mysql_pconnect("localhost", "username", "password");
if ($db)
{
echo "ERROR: Could not connect to database. Please try again later,";
exit;
}
mysql_select_db("testform");
$query = "insert into testform values
('".$firstName."', '".$lastName."')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows()." record inserted into database.";
?>
</body>
</html>
Thanks in advance,
Ed Waite