Greetings! I'm trying to create a form that writes to a MySQL DB using PHP, that will allow a visitor to insert a recipe. But, it doesn't add the data to the DB. I think it's a problem between the form and the php script that adds it to the DB. I think that, because it doesn't throw ANY PHP or MySQL error messages up. Here's the PHP script:
<?php
//Get data from form:
if (isset ($_POST['submit'])) {
print 'Connected to form...<br>';
//Connect to DB:
if ($dbc = @mysql_connect ('localhost', 'usernamei', 'password'))
{
//Select to DB:
if (!@mysql_select_db ('zcms'))
{
die ('Could not select the database because:' . mysql_error() . '<br>');
}
} else {
die ('Could not connect to Mysql because:' . mysql_error() . '<br>');
}
//Write to the DB:
$query = "INSERT INTO `recipe` ( `inc` , `name` , `title` , `ingredients` , `directions` )
VALUES (
'', '{$_POST['name']}', '{$_POST['title']}', '{$_POST['ing']}', '{$_POST['dir']}'
)";
//Add the entry:
if (@mysql_query ($query)) {
print 'The entry has been added';
} else {
print "Could not add the entry because:" . mysql_error() . "Sorry! <br>";
}
//Close connection:
mysql_close();
print '<br>it worked!';
}
//If else, print:
else {
print 'error!!!';
}
?>
And here's the form that submits the data:
<form action="zms.php" method="post" name="submit" id="submit">
<p>
<input name="name" type="text" value="Your Name">
</p>
<p>
<input name="title" type="text" value="Recipe Title">
</p>
<p>
<input name="ing" type="text" value="Ingredients">
</p>
<p>
<textarea name="dir" cols="20">Directions</textarea>
</p>
<p>
<input type="submit" name="Submit" value="Add to the Cook Book!">
</p>
</form>
Can any of you spot any errors that could be causing this problem (keeping data from being inserted into the D😎?
Thank you very much in advance,
Zak