...

View Full Version : mysql Insert INTO tablename problum



Azeem Hassni
08-14-2012, 06:16 PM
hello guys !
how are you all !
i am facing a problum from las 20 mints .
i have created a form to insert data into the database !
when i filled the form and pressed Submit !
that says " Your post has been added ! "
but i gone to phpmyadmin to see the Data .
so no data was there .

so my queston is that why the form not inserting data in database ?
plz any one can help me .

this is the Code





echo "<h3> Post Comment to Guestbook </h3>";

if ($_POST['postbtn']){
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);

if ($name && $email && $message){

$time = date("h:i A");
$date = date("F d, Y");
$ip = $_SERVER['REMOTE_ADDR'];

##########################################################
# Here We are Geting the form data to insert in database #
##########################################################
mysql_query("INSERT INTO gb (name, email, message, time, date, ip,) VALUES (
'$name', '$email', '$message', '$time', '$date', '$ip',)");
echo "Your Posted has been added ! ";
}
else
echo "All fields are required !";
}

echo "<form method='POST' action='./gb.php'>
<table>
<tr>
<td>Name:</td>
<td><input type='text' name='name' style='width: 200px;' /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type='text' name='email' style='width: 200px;' /></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name='message' style='width: 200px; height: 100px;'> </textarea></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='postbtn' value='submit' /></td>
</tr>
</table>


";






sorry for my english .
and thanks in Advance !

Fou-Lu
08-14-2012, 07:57 PM
There's no control here that verifies that the mysql_query operation was successful. The your post has been added message happens so long as $name, $email and $message are not false variables.
Just looking at this query you have syntax errors:


INSERT INTO gb (name, email, message, time, date, ip,)
VALUES ('$name', '$email', '$message', '$time', '$date', '$ip',)

You have trailing commas in both. Add an or die(mysql_error()) to the mysql_query function call, or capture it in an if() branch to determine if it was actually successful or threw an error.


BTW, both time and date are theoretically listed as allowed reserved words. That is, they are considered keywords in MySQL, but due to popular use of field naming in the past, oracle has allowed them to go through as unquoted and still resolve to the proper field. You really should rename them or backtick them to ensure they will work in future versions (which they likely will retain the current rule set in anyway).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum