I am doing a very simple insert into my database but it doesn't seem to be working. I'm following a PHP and MySQL book it's pretty straightforward but I've gotten to a section where I need to insert something into a database but it's not working. I'm using GoDaddy shared hosting as my MySQL database. My code is the following:
HTML page:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Add a Phonebook</title>
</head>
<body>
<h1>Add a Phonebook</h1>
<form method="GET" action="example8-2.php">
<table>
<tr>
<td>Surname</td>
<td><input type="text" name="surname" size=50>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstname" size=100>
</tr>
<tr>
<td>Phone Number</td>
<td><input type="text" name="phone" size=20>
</tr>
</table>
<br><input type="submit">
</form>
</body>
</html>
PHP processing
<?php
require "db_login.php";
require_once "HTML/Template/ITX.php";
if (!empty($_GET["surname"]) &&
!empty($_GET["firstname"]) &&
!empty($_GET["phone"]))
{
if (!($connection = @ mysql_connect("$db_host", "$db_username", "$db_password")))
die("Could not connect to the database.");
$surname = mysqlclean($_GET, "surname", 50, $connection);
$firstname = mysqlclean($_GET, "firstname", 50, $connection);
$phone = mysqlclean($_GET, "phone", 20, $connection);
if (!mysql_select_db("$db_database", $connection))
showerror();
$query = "INSERT INTO phonebook VALUES (NULL, '{$surname}', '{$firstname}', '{$phone}')";
if (!(@mysql_query($query, $connection)))
showerror();
$template = new HTML_Template_ITX("./templates");
$template->loadTemplatefile("example8-3.tpl", true, true);
$template->setCurrentBlock();
$template->setVariable("SURNAME", $surname);
$template->setVariable("FIRSTNAME", $firstname);
$template->setVariable("PHONE", $phone);
$template->parseCurrentBlock();
$template->show();
}
else
header("Location: example8-1.html");
?>
Does anyone have any idea what could be going wrong here?