| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| New Member Join Date: Aug 2005
Posts: 17
![]() | 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: ????: NamePros.com http://www.namepros.com/programming/113511-mysql-database-connection.html $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 Join Date: May 2004
Posts: 5,040
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | (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. ????: NamePros.com http://www.namepros.com/showthread.php?t=113511 And what is actually WRONG with your query is: You forgot a value for the "vcode" field |
| |
| | #3 (permalink) |
| Senior Member Join Date: May 2005 Location: I'm right here
Posts: 3,526
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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...')
__________________ WP Theme Developer Your One-stop for Premium Magazine/CMS WordPress Themes Deluxe Themes |
| |
| | #4 (permalink) |
| DNOA Member Join Date: May 2004
Posts: 5,040
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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" |
| |
| | THREAD STARTER #5 (permalink) |
| New Member Join Date: Aug 2005
Posts: 17
![]() | 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: ????: NamePros.com http://www.namepros.com/showthread.php?t=113511 PHP Code: |
| |
| | #6 (permalink) | ||||
| NamePros Regular Join Date: Jun 2004
Posts: 587
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
????: NamePros.com http://www.namepros.com/showthread.php?t=113511 You can use a variable name for a table name. I do it all the time. -Bob
__________________ Can't wait to be out of this forsaken business. Getting close! :) | ||||
| |
| | #7 (permalink) |
| Senior Member Join Date: May 2005 Location: I'm right here
Posts: 3,526
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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.
__________________ WP Theme Developer Your One-stop for Premium Magazine/CMS WordPress Themes Deluxe Themes |
| |
| | #8 (permalink) |
| DNOA Member Join Date: May 2004
Posts: 5,040
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 <_< |
| |
| | THREAD STARTER #9 (permalink) |
| New Member Join Date: Aug 2005
Posts: 17
![]() | Ok, here's the full code for that page: PHP Code: |
| |
| | #13 (permalink) |
| Senior Member Join Date: May 2005 Location: I'm right here
Posts: 3,526
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Some times empty lines, comments, spaces cause this error, It happened with me..and it is usually fixed by removing that stuff.
__________________ WP Theme Developer Your One-stop for Premium Magazine/CMS WordPress Themes Deluxe Themes |
| |
| | #15 (permalink) |
| NamePros Member Join Date: Jan 2005 Location: Texas USA
Posts: 71
![]() | Try this code. Worked perfectly for me on my test server... PHP Code:
__________________ I wonder... |
| |
| | THREAD STARTER #16 (permalink) |
| New Member Join Date: Aug 2005
Posts: 17
![]() | 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 Join Date: May 2004
Posts: 5,040
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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. |
| |
| | #20 (permalink) |
| NamePros Member Join Date: Jan 2005 Location: Texas USA
Posts: 71
![]() | 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... |
| |
![]() |
| 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 10:46 PM |
| HOW TO: Use shell to control MySQL. | abdulmueid | Webmaster Tutorials | 16 | 08-27-2005 09:17 AM |
| Help needed for connection to MYSQL database | chelsea | Programming | 5 | 05-19-2005 12:55 AM |
| Tutorial: Getting Started With MySQL (The Basics) | deadserious | Webmaster Tutorials | 3 | 04-18-2004 02:17 PM |