I am at a loss... I have tried everything I can find to do in my text book but this script is only working partly.
I am attempting to enter data into a MySQL Database. The table where the data should go is called 'discs'. If I don't fill out all the fields I get an error saying such (which I should). However, if I DO fill out all the field, the page loads the <h1> Header but then just stops. No error... No "1 disc inserted into database"... nothing!
Here is my PHP Code... can ANYONE help me?
<html>
<head>
<title>Add Disc</title>
</head>
<body>
<h1>Disk Entry Results</h1>
<?
if (!$system || !$title || !$rating || !$discs || !$loaned)
{
echo "You have not entered all the required details.<br>"
."Please go back and try again.";
exit;
}
$system = addslashes($system);
$title = addslashes($title);
$rating = addslashes($rating);
$discs = doubleval($discs);
$loaned = doubleval($loaned);
@ $db = mysql_pconnect("localhost", "my_username", "my_password");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("discs");
$query = "insert into discs values ('".$system."', '".$title."', '".$rating."', '".$discs."', '".$loaned."')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows()." disc inserted into database.";
?>
</body>
</html>
This comes right out of my text book but I have heard from severals that there are errors in the lessons all throughout the book.
Also... AFTER I get this working correctly, is there a way to submit the confirmation message / error inside my html templates instead of just using this nasty looking page?