Want connect to Database??
Posted: Sat May 17, 2008 3:09 pm
Hey,
I am trying to submit from data from this form:
Into my database with this php code:
***** PLEASE DO NOT POST PASSWORDS *****
Everytime i click submit is runs through the code and displays:
Why will it not submit the data to the database?
Thanks!!
I am trying to submit from data from this form:
Code: Select all
<form action="blog2.php" method="post">
Your Name:<br> <input type="text" name="name" style="color: #000000; background-color: #E0E0E0"><br>
E-mail: <br><input type="text" name="email" style="color: #000000; background-color: #E0E0E0"><br>
Comments:<br><textarea name="comments" style="color: FFFFFF; background-color: #E0E0E0;
font-size= 18px" cols = "80" rows = "30" >
</textarea><br><br>
<input type="submit" style="color: #000000; background-color: #E0E0E0" value="Add New Post">
</form>Into my database with this php code:
***** PLEASE DO NOT POST PASSWORDS *****
Code: Select all
<?php
// create short variable names
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
if (!$name || !$email || !$comments)
{
echo 'You have not entered all the required details.<br />'
.'Please go back and try again.';
exit;
}
$db = mysql_connect('localhost', 'root', 'xxxxxxxx');
mysql_select_db('blog');
$db = mysql_connect('localhost', 'root', 'xxxxxxxx');
if (!$db) {
(die . 'Could not connect' . mysql_error());
}
$link = mysql_select_db('blog');
if ($link)
echo 'Connected';
else
echo 'not connected';
echo '<br></br>';
$sql = ("INSERT INTO contents VALUES (1,'name', 'email', 'comments';");
$query = mysql_query($db);
$query = mysql_query($sql);
if($query)
echo $db->affected_rows.' book inserted into database.';
else
echo 'Data not entered!';
?>Everytime i click submit is runs through the code and displays:
Code: Select all
Connected
Data not entered!Why will it not submit the data to the database?
Thanks!!