Why can't I add data into the table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dhin
    New Member
    • Mar 2011
    • 1

    Why can't I add data into the table?

    How can I fix this?


    This is the warning:

    Code:
    Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\pos\addmessage.php  on line 4

    This is the code:

    Code:
    <?php
    mysql_connect("localhost","root","");
    @mysql_select_db("pointofsales") or die ("Unable to connect");;
    $sql=mysql_query("INSERT INTO products(prodid, prodname, description, amount, stocks)VALUES('$_POST[ProdID]','$_POST[ProdName]','$_POST[Description]','$_POST[Amount]','$_POST[Stocks]')";
    mysql_query($sql);
    mysql_close();
    echo "Record is added successfully";
    ?>
    I'm a beginner. I would appreciate your help. Thanks!
  • Mayur2007
    New Member
    • Aug 2007
    • 67

    #2
    Hello,

    Try the below code

    Code:
    <?php
        mysql_connect("localhost","root","");
        @mysql_select_db("pointofsales") or die ("Unable to connect");;
        $sql = "INSERT INTO products(prodid, prodname, description, amount, stocks)
                                VALUES ('".$_POST[ProdID]."',
                                        '".$_POST[ProdName]."',
                                        '".$_POST[Description]."',
                                        '".$_POST[Amount]."',
                                        '".$_POST[Stocks]."');";
        $sql=mysql_query($sql);
        if(mysql_query($sql)) {    
            echo "Record is added successfully";
        } else {
            echo "There is some error";
        }
        mysql_close();
    ?>

    Comment

    • MrMancunian
      Recognized Expert Contributor
      • Jul 2008
      • 569

      #3
      Look at line 3, there's a double semicolon... The error tells you it's row 4 and most of the times, the error is one row earlier.

      Steven

      Comment

      Working...