Hello and welcome to our community! Is this your first visit?
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
    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:

    $database "carcatalog";
    $connection mysql_connect($host,$user,$password)
    OR DIE (
    "Unable to connect to database! Please try again later.");
    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");



    Last edited by guelphdad; 08-23-2006 at 03:30 PM.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    St. Catharines, Ontario Canada
    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");
    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:

    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