| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| New Member | mySQL database connection Ok, I have a registration area on my site, and when people sign up their information goes to my admin section. Since The script I am using doesn't use the "First Name" and "Last Name" fields, I added them to my database and I am trying to send them to my admin section, but it says "cannot execute query 3". Here is the code I am using for query 3: $ip = $_SERVER['REMOTE_ADDR']; $query = "INSERT INTO $userstable (username,password,email,vcode,address,city,state, zip,ip,firstname,lastname,) VALUES ('$_POST[username]','$_POST[password]','$_POST[email]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zip]','$ip','$_POST[FirstName]','$_POST[LastName]')"; $resultB = mysql_query($query,$connection) or die ("Coundn't execute query3."); What am i doing wrong? |
| |
| | #2 (permalink) |
| DNOA Member | (Please use PHP and CODE tags from now on!) Also, space your code better... it's not uniform and hard to read. I'd also recommend recommend turning the $_POST variables into short names: PHP Code: As for your problem, I don't think that you can use a variable as a table name... correct me if I'm wrong, since I've never tried it, but try just using the table name! Putting a variable to it takes more time anyway. And what is actually WRONG with your query is: You forgot a value for the "vcode" field
__________________ codeboards A high-quality community of programmers -- Join today and post! We want new members! |
| |
| | #3 (permalink) |
| Senior Member | Did you try die(mysql_error()) instead for better error reporting. I think the problem remains in this part of the query "INSERT INTO $userstable (username,password,email,vcode,address,city,state, zip,ip,firstname,lastname,) These are 11 columns, but the values are only 10, and there's no order. What's the vcode column? Also note the , after lastname. I do not think you need to specify column names before values if you will use enter data in all columns in order, like INSERT INTO table VALUES('', '$first..name', '$etc...')
__________________ Custom WordPress theme design. Top notch free WordPress themes Custom Theme Design |
| |
| | #4 (permalink) |
| DNOA Member | Designporte - True, you don't need to specify the column names, however it can be useful for inserting data into only a few specific fields. Yep, so in summary, your errors are, Balkee867: 1. You forgot to put a value into "vcode" field, 2. You put a comma after "lastname"
__________________ codeboards A high-quality community of programmers -- Join today and post! We want new members! |
| |
| | #5 (permalink) |
| New Member | Ok, thanks a lot for that problem, didn't realize I forgot a value and that I had an extra comma. Anyways, now it is adding the user to the admin page, but the new fields that i added (firstname and lastname) are both blank. It also says: PHP Code: |
| |
| | #6 (permalink) | |
| NamePros Regular | Quote:
You can use a variable name for a table name. I do it all the time. -Bob
__________________ The mass purge has begun. | |
| |
| | #7 (permalink) |
| Senior Member | This error is showing because the output is already sent and you are trying to modify header information somehow. We need detailed code to know where the problem contains. As it seems you are trying to send headers some how after headers are already sent. Please show more source code.
__________________ Custom WordPress theme design. Top notch free WordPress themes Custom Theme Design |
| |
| | #8 (permalink) |
| DNOA Member | Yeah, thanks bob! ^_^ As for your error, (You didn't have to put THAT in a PHP tag. lol... just put PHP in a PHP tag ) that means that you've sent headers (or something else to the browser, such as text or an echo() statement) already... a view of your full script if you could post it would be MOST helpful in solving the problem.Hey, what's up with the spaces in your filename: ".ph__p"? (Replace _ with a space...) - look at that header error... EDIT: Designporte beat me to it <_<
__________________ codeboards A high-quality community of programmers -- Join today and post! We want new members! |
| |
| | #9 (permalink) |
| New Member | Ok, here's the full code for that page: PHP Code: |
| |
| | #13 (permalink) |
| Senior Member | Some times empty lines, comments, spaces cause this error, It happened with me..and it is usually fixed by removing that stuff.
__________________ Custom WordPress theme design. Top notch free WordPress themes Custom Theme Design |
| |
| | #15 (permalink) |
| NamePros Member | Try this code. Worked perfectly for me on my test server... PHP Code:
__________________ I wonder... |
| |
| | #16 (permalink) |
| New Member | Since I tried yours, and it still didn't work, it must be what I have before the <?php . Is there something that would cause this error in the following code? PHP Code: |
| |
| | #17 (permalink) |
| DNOA Member | Ah! You should have sent the WHOLE file to us. You cannot have ANY DATA sent to the browser BEFORE a header statement or setcookie() function (which uses headers). This means no HTML ... no CSS ... no echo() statements, etc. You will have to put the PHP first, or divide it into seperate files.
__________________ codeboards A high-quality community of programmers -- Join today and post! We want new members! |
| |
| | #19 (permalink) |
| DNOA Member | No, before ANY HTML or ANYTHING that sends data to the browser. Before any output, before any other headers.
__________________ codeboards A high-quality community of programmers -- Join today and post! We want new members! |
| |
| | #20 (permalink) |
| NamePros Member | setcookie has to be set BEFORE ANYTHING is shown ![]() To do it your way, you could put all the data into a variable like you did the form and echo it when needed, or place it into a seperate file and include it when needed...
__________________ I wonder... |
| |
| | #21 (permalink) |
| DNOA Member | ...which is just what I said
__________________ codeboards A high-quality community of programmers -- Join today and post! We want new members! |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tutorial: How to Install Apache2 MySQL and PHP on Windows | deadserious | Webmaster Tutorials | 35 | 09-21-2005 09:46 PM |
| HOW TO: Use shell to control MySQL. | abdulmueid | Webmaster Tutorials | 16 | 08-27-2005 08:17 AM |
| Help needed for connection to MYSQL database | chelsea | Programming | 5 | 05-18-2005 11:55 PM |
| Tutorial: Getting Started With MySQL (The Basics) | deadserious | Webmaster Tutorials | 3 | 04-18-2004 01:17 PM |