Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with "INSERT INTO"

Status
Not open for further replies.

jjack46

Programmer
Jul 29, 2013
10
AU
I am a relative newbie, I have some programming experience in PHP and Mysql but haven't done much for a few years. I am writing a program that requires the user to input data. I have written the following "INSERT" queries and cannot understand why I get the results that I do.

1) This works in the program and in the PHPMyAdmin sql tab for the table-
"INSERT INTO Player(PlayerNo, Surname, FirstName, PreferredName, Dob, Street, TownSuburb, State, Postcode, AgeAtStart, Handicap, Grade, StateRep, Status) VALUES (NULL, 'Smith', 'Peter', 'Pete', '1976-03-10','5 Broad St', 'Kingston', 'Qld', '4114', '38', '16', 'B', 'Qld', 'Police')"

2) This works in the PHPMyAdmin sql tab for the table but not in the program -
"INSERT INTO `Group` (`GroupId`, `GroupNo`, `Day`, `Tme`) VALUES (NULL, '5', '2', 'AM')"

3) This doesn't work in either -
"INSERT INTO Group (GroupId, GroupNo, Day, Tme) VALUES (NULL, '5', '2', 'AM')"

As you can see the syntax is quite differently in the two that work but the same in (1) and (2) where one works and one doesn't.

Any suggestions.
 
#3 is easy to understand why it doesn't work. In MYSQL and most databases the word "Group" is a reserved word as in "Group By". Which means you can't just use it without the back ticks around it because you tell MYSQL to do something in a place its not supposed to be in.

For the other 2, we'd need to see the queries in context in your PHP code.

As a tip, when you need to know why a query fails from PHP most DB libraries have ways to get the DB errors back. In the case of the standard mysql php library you could use mysql_error() function to see why the queries are failing.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
A silly mistake that I should have picked up. I've got it working now. Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top