[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 01-01-2007, 10:16 PM   #1 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

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 behold


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
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, 10:20 PM   #2 (permalink)
AzN
SI: ServiceInteract
 
AzN's Avatar
 
Join Date: May 2006
Location: ServiceInteract
Posts: 2,551
0.96 NP$ (Donate)

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
AzN is offline  
Old 01-01-2007, 10:22 PM   #3 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

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 behold


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, 10:31 PM   #4 (permalink)
AzN
SI: ServiceInteract
 
AzN's Avatar
 
Join Date: May 2006
Location: ServiceInteract
Posts: 2,551
0.96 NP$ (Donate)

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");
AzN is offline  
Old 01-01-2007, 10:33 PM   #5 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

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 behold


isnt it the samething or did u change something from it?
unknowngiver is offline  
Old 01-01-2007, 10:45 PM   #6 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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, 04:01 AM   #7 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

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 '.

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 04:15 AM.
Matthew. is offline  
Old 01-02-2007, 04:02 AM   #8 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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
Quote:
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.



EDIT Looks like Matthew. just beat me

Last edited by filth@flexiwebhost; 01-02-2007 at 04:10 AM.
Peter is offline  
Old 01-02-2007, 04:08 AM   #9 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

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
Quote:
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());
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, 04:10 AM   #10 (permalink)
Ultima Ratio Regum
 
Redleg's Avatar
 
Join Date: Sep 2003
Location: Up North
Posts: 2,083
71.00 NP$ (Donate)

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 behold


Edit: *remider to self: Alway refresh before posting*
Someone beat me to it..
__________________
|Internet, Games, Computer Talk|IP Whois + Geolocation|Geolocate your IP|
|Dynamic Forum Sigs|2,900+ Free Flash Games|

<meta name="Jedi Mind Trick" content="Buy my domains, you will!">
VoIPUSA.com-MyBlogging.com-ArrivingSoon.com-Nano.tv- Technology.ws-Ammo.us-Racing.cc-Privacy.ws
Redleg is offline  
Old 01-02-2007, 04:09 PM   #11 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

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 behold


yup it was the '
thanks
unknowngiver is offline  
Old 01-02-2007, 05:19 PM   #12 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 09:42 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85