Data isn't saving to mysql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nse111
    New Member
    • Jul 2008
    • 21

    Data isn't saving to mysql database

    I hv a form in my php file to accept some data from the user.

    Then as shown below I capture the data using PHP.

    the data is getting captured in the variables no prob with that.

    but the data isn't getting saved to the database.

    it should have something to do with my if cluases. pls let me knw the error.

    thanks in advance...!!!! :)

    [code=php]
    <?php
    if (isset($_POST['btnok']))
    {
    $image_id = $_GET['id'];

    $title = $_POST['lsttitle'];
    $fname = $_POST['txtfname'];
    $lname = $_POST['txtlname'];
    $email = $_POST['txtemail'];
    $message = $_POST['txtmessage'];

    echo "$title........ ";
    echo"<br />";


    $db_host = 'localhost';
    $db_user = 'root';
    $db_pwd = 'dba';

    $database = 'gallery';

    if (!mysql_connect ($db_host, $db_user, $db_pwd)) die("Can't connect to database");

    if (!mysql_select_ db($database)) die("Can't select database");

    if ($message==null or $fname==null)

    {
    echo "Please fill all required fields";
    }

    elseif ($fname==null or $lname==null)

    {
    echo "Please fill all required fields";
    }

    else

    {
    $result = mysql_query("in sert into inquiries(i_inq _title, i_inq_fname, i_inq_lname, i_inq_email, i_inq_message, i_inq_painting_ id) values ('".$title."' , '".$fname."' , '".$lname."' , '".$email."' , '".$message. "', '".$image_id."' )") or die("MYSQL Returned: ". mysql_error());

    if($result==fal se)

    {
    echo "Couldnt complete the inquiry please try again!";
    }

    else

    {
    echo"did it";
    //mysql_close();
    }
    }
    }

    ?>
    [/code]
    Last edited by pbmods; Aug 7 '08, 10:45 AM. Reason: Added CODE tags.
  • nse111
    New Member
    • Jul 2008
    • 21

    #2
    and one of those $fname within if() should be $email. sorry mistyped.

    I get this smg all the time. just cnt c y

    "Please fill all required fields"

    Comment

    • nse111
      New Member
      • Jul 2008
      • 21

      #3
      sorry it's a silly question. found the answer. for anyone who seeks tha answer it's simply that the

      or


      should be

      ||

      Comment

      Working...