Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    30
    Thanks
    10
    Thanked 1 Time in 1 Post

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •