NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Query error

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 01-01-2007, 11:16 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes

Query error


Hey
i am getting a querry error from this line:
PHP Code:
        $query "INSERT INTO `mpg` ('id','Manufacturer','Year','Car Name','Miles Per Gallon City',
                  'Miles Per Gallon Freeway','Year Gas Price') 
                  VALUES ('','
$manufacturer','$year','$car_name','$mpgc','$mpgf','$year_gas_price')";
        
mysql_query($query) or die ("Error, insert query failed"); 
it gives the "Error,insert query failed" error...and i have 2 questions
????: NamePros.com http://www.namepros.com/programming/275776-query-error.html
1. If there is any visible problem in that piece of code
2. How can i make it show the actual error instead of the die command that i gave it..if i remove that die command..it shows nothing..
unknowngiver is offline  
Old 01-01-2007, 11:20 PM   #2 (permalink)
AzN
is on hiatus
Join Date: May 2006
Posts: 2,453
AzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond repute
 


Find Marrow Donors! Ethan Allen Fund Ethan Allen Fund Ethan Allen Fund Save a Life Save a Life Save a Life Save a Life Save a Life Save a Life VA Tech Memorial VA Tech Memorial VA Tech Memorial VA Tech Memorial Save a Life Save a Life Save a Life
'$ mpgf' should be '$mpgf
__________________
Currently on hiatus. Back whenever.
AzN is offline  
Old 01-01-2007, 11:22 PM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
hm it is like that..i duno y it added that space when i copy pasted it here :-s

$query = "INSERT INTO mpg ('id','Manufacturer','Year','Car Name','Miles Per Gallon City',
'Miles Per Gallon Freeway','Year Gas Price')
VALUES ('','$manufacturer','$year','$car_name','$mpgc','$ mpgf','$year_gas_price')";
mysql_query($query) or die ("Error, insert query failed");
unknowngiver is offline  
Old 01-01-2007, 11:31 PM   #4 (permalink)
AzN
is on hiatus
Join Date: May 2006
Posts: 2,453
AzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond reputeAzN has a reputation beyond repute
 


Find Marrow Donors! Ethan Allen Fund Ethan Allen Fund Ethan Allen Fund Save a Life Save a Life Save a Life Save a Life Save a Life Save a Life VA Tech Memorial VA Tech Memorial VA Tech Memorial VA Tech Memorial Save a Life Save a Life Save a Life
mysql_query("INSERT INTO mpg ('id','Manufacturer','Year','Car Name','Miles Per Gallon City',
'Miles Per Gallon Freeway','Year Gas Price')
VALUES ('','$manufacturer','$year','$car_name','$mpgc','$ mpgf','$year_gas_price'")or die ("Error, insert query failed");
__________________
Currently on hiatus. Back whenever.
AzN is offline  
Old 01-01-2007, 11:33 PM THREAD STARTER               #5 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
isnt it the samething or did u change something from it?
unknowngiver is offline  
Old 01-01-2007, 11:45 PM   #6 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
It's the same thing.. >__>

Run the query in phpMyAdmin and post the error it gives you. I don't see anything that would just be wrong on its own, unless you can't have spaces in the column titles. The only other thing I see is ' around column names.. shouldn't it be ` or nothing?

If you used spaces between items, it wouldn't put that space in by itself into $mpgf
Dan is offline  
Old 01-02-2007, 05:01 AM   #7 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
Always added error reporting to every query, this will gve you a more descriptive error as Dan said phpmyadmin will.

Run this:
PHP Code:
 $query "INSERT INTO `mpg` ('id','Manufacturer','Year','Car Name','Miles Per Gallon City',
                  'Miles Per Gallon Freeway','Year Gas Price') 
                  VALUES ('','
$manufacturer','$year','$car_name','$mpgc','$  mpgf','$year_gas_price')";
        
mysql_query($query) or die ("Error, insert query failed" mysql_error()); 
Note the mysql_error() has been added.

The problem is (i suspect) that you are not using backticks for field names, instead you are using '.
????: NamePros.com http://www.namepros.com/showthread.php?t=275776

Correct query should be:
Code:
INSERT INTO `mpg` (`id`,`Manufacturer`,`Year`,`Car Name`,`Miles Per Gallon City`,
                  `Miles Per Gallon Freeway`,`Year Gas Price`) 
                  VALUES ('','$manufacturer','$year','$car_name','$mpgc','$  mpgf','$year_gas_price')
Last edited by Matthew.; 01-02-2007 at 05:15 AM.
Matthew. is offline  
Old 01-02-2007, 05:02 AM   #8 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by unknowngiver
2. How can i make it show the actual error instead of the die command that i gave it..if i remove that die command..it shows nothing..
Change:-

PHP Code:
or die ("Error, insert query failed"); 
To the following:-


PHP Code:
or die (mysql_errno().' : '.mysql_error()); 
Best to change it before the site goes into production tho as people can work out how your database is made from the errors.
????: NamePros.com http://www.namepros.com/showthread.php?t=275776



EDIT Looks like Matthew. just beat me
Last edited by filth@flexiwebhost; 01-02-2007 at 05:10 AM.
Peter is offline  
Old 01-02-2007, 05:08 AM   #9 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
Originally Posted by filth@flexiwebhost
Change:-

PHP Code:
or die ("Error, insert query failed"); 
To the following:-


PHP Code:
or die (mysql_errno().' : '.mysql_error()); 
????: NamePros.com http://www.namepros.com/showthread.php?t=275776
Beat ya

Quote:
Best to change it before the site goes into production tho as people can work out how your database is made from the errors.
Now i've never agreed with that, if someone is in a position where they can executer a query they don't need to know table/field names...You can get those by running a query.

(having said that i normally extend my error logger into the mysql class so they do get hidden)
Matthew. is offline  
Old 01-02-2007, 05:10 AM   #10 (permalink)
Ultima Ratio Regum
 
Redleg's Avatar
Join Date: Sep 2003
Location: Up North
Posts: 2,082
Redleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to beholdRedleg is a splendid one to behold
 



Edit: *remider to self: Alway refresh before posting*
Someone beat me to it..
__________________
IP Whois + Geolocation|Geolocate your IP|Dynamic Forum Sigs
<meta name="Jedi Mind Trick" content="Buy my domains, you will!">
Redleg is offline  
Old 01-02-2007, 05:09 PM THREAD STARTER               #11 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
yup it was the '
thanks
unknowngiver is offline  
Old 01-02-2007, 06:19 PM   #12 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
That's why being lazy is good. If you didn't put anything around those, it would have worked.
Dan is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:42 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger