I'm trying to make a script that inserts data into a MySQL database via using a form. Here is my form code:
<html>
<head>
<title>Unrealism - Add Interview</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../../style.css" rel="stylesheet" type="text/css">
</head><body background="../../images/topbg.png">
<?PHP
echo "<p><font size=\"5\">Add Interview</font></p>"
."<table width=\"70%\" border=\"0\" cellspacing=\"1\">"
."<tr>"
."<td width=\"17%\">Interviewer Name:</td>"
."<td width=\"83%\"><form method=\"post\" action=\"done.php3\"><input name=\"name\" type=\"text\" size=\"50\"></td>"
."</tr>"
."<tr>"
."<td width=\"17%\">Interview Title:</td>"
."<td width=\"83%\"><input name=\"title\" type=\"text\" size=\"50\"></td>"
."</tr>"
."<tr>"
."<td width=\"17%\">Description:</td>"
."<td width=\"83%\"><input name=\"desc\" type=\"text\" size=\"50\"></td>"
."</tr>"
."<tr>"
."<td valign=\"top\">Interview:</td>"
."<td>"
."<textarea name=\"body\" cols=\"50\" rows=\"5\"></textarea>"
."</td>"
."</tr>"
."<tr>"
."<td valign=\"top\">Submit:</td>"
."<td>"
."<input type=\"submit\" name=\"submit\" value=\"Submit\">"
."<input name=\"reset\" type=\"reset\" id=\"Reset\" value=\"Reset\">"
."</form></td>"
."</tr>"
."</table>";
?>
</body>
</html>
The form passes all the info on to done.php. Here is done.php:
<html>
<head>
<title>Unrealism - Add Interview</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?PHP
// Connects to database
@ $db = mysql_pconnect("#####", "#####", "######");
if (!$db)
{
echo "Error: Could not connect to the database. Check that you entered the connection details correctly.";
exit;
}
mysql_select_db("unrealism");
// Includes Unrealism header
require_once("../../includes/header.php");
// Checks to make sure all fields are filled out
if (!$name || !$title || !$desc || !$body)
{
echo "You have not entered all the required details.<br>"
."Please go back and try again.";
exit;
}
// Inserts data into database
$query = "INSERT INTO interviews
(name, title, date, desc, body)
VALUES
('$name', '$title', 'now()', '$desc', '$body')";
// Checks to see if data was entered correctly
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows()." Interview inserted into database successfully.";
else
echo "Interview entered un-successfully.<p>";
echo "<a href=\"javascript:history.back();\">Go Back</a><br>";
echo "<a href=\"../../admin/index.php3\">Admin Index</a><br>";
echo "<a href=\"../../index.php\">Main Index</a>";
// Includes Unrealism footer
require_once("../../includes/footer.php");
?>
</body>
</html>
When I click submit on the forum I get:
Interview entered un-successfully.
Meaning something is screwed up with done.php. Can anyone see anything wrong?