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 to the CF scene
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    i need some help on my php output can someone help me th

    i keep getting couldn;t execute query when i wish to add things to my database
    below is my code
    can some one point out the mistake for me thank you


    PHP Code:
    <head>
      <title>Hello!</title>
    </head>

    <body>
      <?php
         $host
    ="mysql153.secureserver.net";
    $user="carcatalog";
    $password="";
    $database "carcatalog";
    $connection mysql_connect($host,$user,$password)
    OR DIE (
    "Unable to connect to database! Please try again later.");
    $dbmysql_select_db("$database",$connection)
    or die (
    "Couldn't connect to database");

    $query"INSERT INTO Car ( Carplate no, Password, Your Name, Your Contact No, Your Email Address, Car Model, Car Registration Date, Engine Capacity, Transmission, Asking Price, Mileage, Fuel Type, Vehicle features, Accessories, Description,COE, COE Expiry Date, OMV,PARF,Number of Owners, Type of Vehicle  )
           VALUES ('$Carplate no', '$Password', '$Your Name', '$Your Contact No', '$Your Email Address', '$Car Model', '$Car Registration Date', '$Engine Capacity', '$Transmission', '$Asking Price', '$Mileage', '$Fuel Type', '$Vehicle features', '$Accessories', '$Description','$COE', '$COE Expiry Date', '$OMV','$PARF','$Number of Owners', '$Type of Vehicle')"
    ;
    $result=  mysql_query($query)
    or die (
    "Couldn't execute query");



    ?>

    </body>

    </html>
    Last edited by guelphdad; 08-23-2006 at 03:30 PM.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    ryan, welcome to codingforums.

    I will note a couple of things for you.

    1) when using php code feel free to enclose them within [ php] and [/php] tags. remove the space in that first tag. I've done that in your post above.

    2) change the following code above:
    or die ("Couldn't execute query");
    to
    or die ("Mice like to eat cheese");
    and I guarantee that is the error message that will show up when you run your query. Not very helpful is it? :-)

    What you want to do is add the mysql error messaging after it like this:

    Code:
    or die ("Couldn't execute query") . mysql_error();
    also add that in the other two places where you have error messages above.

    that will now actually produce the error that mysql is complaining about and you can see what the problem is.

    I'll go ahead and guess that the error is that you have spaces in the column names you are referring to in your code. You can't create a column with a space in the name in mysql.

    Another thing you should read about when you have time is database normalization. This concept will help you design more efficient tables that will query better and faster.

    Here is an article that will introduce you to that concept.
    Last edited by guelphdad; 08-23-2006 at 03:38 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
    •