View Full Version : i need some help on my php output can someone help me th

08-23-2006, 11:56 AM
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


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




08-23-2006, 03:36 PM
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 (http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html) is an article that will introduce you to that concept.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum