Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-14-2012, 06:16 PM   PM User | #1
Azeem Hassni
New Coder

 
Join Date: May 2012
Posts: 14
Thanks: 7
Thanked 0 Times in 0 Posts
Azeem Hassni is an unknown quantity at this point
mysql Insert INTO tablename problum

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

PHP 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 !

Last edited by Azeem Hassni; 08-14-2012 at 06:20 PM..
Azeem Hassni is offline   Reply With Quote
Old 08-14-2012, 07:57 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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:
Code:
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.

Edit:
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).

Last edited by Fou-Lu; 08-14-2012 at 08:00 PM..
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:23 AM.


Advertisement
Log in to turn off these ads.