PHP with MySQL INSERT problem
Hello, I am looking for advice on some code I am writing. I am trying to ceat a database driven page for my company website where we will list all of the used equipment we are wanting to sell. What I am currently trying to do is make the page where I will ad the equipment into the database table. This page has a few text boxes for the equipments make, model, engine size, price, etc. It also has two drop down boxes. The first drop down box is to pick which category of equipment the pices being added is in and the second box is to pick the manufacturer (make) of the piece of equipment. As of now everything seems to work except that no matter which category I choos from the list, when I go back and check the database manually it is always category one listed in that field. I have tried a few different methods, but I always get the same results. If anyone has any suggestions I would greatly appreciate your input. I am including the code for your review:
PHP Code:
Thank you, in advance, for your help! |
Some classical debugging should be done here.
First look at the HTML which is produced for the drop down lists. Does it have the correct option values? If not, look at the loops to create the drop down list. Then print out the POST array you are receiving back. Are the values for the drop down lists correct in this array? If not, check the form in the HTML code. If the post array has the correct contents, print out the INSERT SQL statement. You must see there an error in the value for the category, at least something else than what you expect. jlinkels |
A little debugging
Thank you for your ideas jlinkels. I looked at my HTML source and all of the values in my drop down list are correct. So I checked my SQL Query and I noticed that the variable for the product make was set incorrectly. I changed that to the correct value and now I get ones for both the category and the make in the database. What is weird is when I had the incorrect value for the make it INSERTed the correct value into the database. That soesn't make any sense to me. If you could help me out with some debugging steps I would really appreciate it. I am pretty unfamiliar with how to do it though. Here is what I updated my code to be:
PHP Code:
|
Okay, almost fixed it...
Alright, I got it to post the correct values, but now it is placing the record into the database twice. Why would it do this? I can't figure it out at all. Here is the code, let me know if you have any ideas.
PHP Code:
|
Come on... what do you see if you print the SQL statements?... you insert it twice by executing the SQL statement twice.
jlinkels |
Not to be stupid, but when you say to print the SQL statements what do you mean? I am brand new at debugging and I'm not sure what you mean. If you could explain it to me I would appreciate it. I know debugging is important and I would like your help in learning what I need to do. I did figure it out though. In the lines directly below where my query is in the code I had two $results variables. The second $result variable was a remnant of using code from one of my other pages that required to SQL statements to place values from two forms into multiple tables. I can't believe I missed that one, but at least I know what to look for if it happens again. I would still like to hear your thoughts on printing SQL statements though. Thank you.
|
Quote:
PHP Code:
And debugging is done by inserting this statement in front your mysql_query statement: PHP Code:
|
All times are GMT -5. The time now is 04:41 AM. |