INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Problem with "INSERT INTO"

Problem with "INSERT INTO"

(OP)
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.

RE: Problem with "INSERT INTO"

#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

RE: Problem with "INSERT INTO"

(OP)
A silly mistake that I should have picked up. I've got it working now. Thanks very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close