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
    Regular Coder
    Join Date
    Feb 2007
    Posts
    217
    Thanks
    25
    Thanked 1 Time in 1 Post

    database empty query

    I'm trying to write some values to my database, however it seems to fail since I'm getting the following error when I want to insert a record:

    Code:
    Warning: mysqli_query() [function.mysqli-query]: Empty query in
    I hope someone can tell me what I'm doing wrong.

    PHP Code:
    $con=mysqli_connect($db_host$db_username$db_password$db_database);


    if (
    mysqli_connect_errno($con))
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }


    $sql=mysqli_query($con,"INSERT INTO myproduct (product, model, price, quantity) VALUES ('hi', 'hixxx', '34', '99999')");
    if (!
    mysqli_query($con,$sql))
      {
      die(
    'Error: ' mysqli_error($con));
      }


    mysqli_close($con); 

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You haven't done anything to verify your query.
    The answer is simple, the query has failed. Standard check of mysqli_error($con); will tell you the cause.
    This is also not doable: if (!mysqli_query($con,$sql)) . If the first one fails, that would trigger the same error as posted, if it was successful it will trigger an error on an incorrect argument datatype. You simply cannot query a query resultset.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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