[PHP] Session migration problem...
During my conversion to use sessions, and turning register globals off, I've run into this problem.. So far the first and only... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/web/timesheetsessions/index.php on line 26 Here are lines 25, and 26: $result = mysql_query(SELECT * FROM `users` WHERE `uname` = '.$_POST['username'].'); $row = mysql_fetch_array($result); Do I have a typo somewhere or something? Or did I fudge something? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session migration problem...
--- Jake McHenry [EMAIL PROTECTED] wrote: $result = mysql_query(SELECT * FROM `users` WHERE `uname` = '.$_POST['username'].'); Don't put uname in single quotes. Aside from that, don't forget that you can interpolate variables with curly braces. Depending on your personal preference, you might find it easier to read: select * from users where uname = '{$_POST['username']}' Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session migration problem...
-Original Message- From: Chris Shiflett [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2003 9:56 PM To: Jake McHenry; [EMAIL PROTECTED] Subject: Re: [PHP] Session migration problem... --- Jake McHenry [EMAIL PROTECTED] wrote: $result = mysql_query(SELECT * FROM `users` WHERE `uname` = '.$_POST['username'].'); Don't put uname in single quotes. Aside from that, don't forget that you can interpolate variables with curly braces. Depending on your personal preference, you might find it easier to read: select * from users where uname = '{$_POST['username']}' Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp Is there any advantage to the curly brackets over the '..'? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session migration problem...
-Original Message- From: Chris Shiflett [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2003 9:56 PM To: Jake McHenry; [EMAIL PROTECTED] Subject: Re: [PHP] Session migration problem... --- Jake McHenry [EMAIL PROTECTED] wrote: $result = mysql_query(SELECT * FROM `users` WHERE `uname` = '.$_POST['username'].'); Don't put uname in single quotes. Aside from that, don't forget that you can interpolate variables with curly braces. Depending on your personal preference, you might find it easier to read: select * from users where uname = '{$_POST['username']}' Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I took the single quotes off of the field name, uname, but still getting the same error at the same line in the file... Any other suggestions? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session migration problem...
-Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2003 10:32 PM To: [EMAIL PROTECTED] Subject: RE: [PHP] Session migration problem... -Original Message- From: Chris Shiflett [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2003 9:56 PM To: Jake McHenry; [EMAIL PROTECTED] Subject: Re: [PHP] Session migration problem... --- Jake McHenry [EMAIL PROTECTED] wrote: $result = mysql_query(SELECT * FROM `users` WHERE `uname` = '.$_POST['username'].'); Don't put uname in single quotes. Aside from that, don't forget that you can interpolate variables with curly braces. Depending on your personal preference, you might find it easier to read: select * from users where uname = '{$_POST['username']}' Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I took the single quotes off of the field name, uname, but still getting the same error at the same line in the file... Any other suggestions? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php HAHA.. Sorry everyone I found my problem... The field name in the table is username, not uname I guess I must have changed that as well. My head is spinning from all the stuff I'm trying to change... My only other question is can I change from '..' to `..`? When I try to run a query on the table name, it has to be within `` instead of ''. I just tried it, it looks like it works... Just want to make sure this is ok. Thanks, Jake -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session migration problem...
--- Jake McHenry [EMAIL PROTECTED] wrote: I took the single quotes off of the field name, uname, but still getting the same error at the same line in the file... Any other suggestions? Sure. Let's look at your original code: $result = mysql_query(SELECT * FROM `users` WHERE `uname` = '.$_POST['username'].'); So, rather than trying to glance at this and figure out what's wrong, I will instead suggest a debugging technique or two. 1. Put your query in a variable like $sql. This can simplify your statement: $result = mysql_query($sql); 2. Don't wait until you use $result to find out it's not a valid resource; test it immediately: if (!$result = mysql_query($sql)) 3. If it's not a valid resource, this conditional statement will be true. You can echo (or send to a log file) the output of mysql_error() to see what MySQL thinks the last error was (which will be the error generated by the query, in this case). Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session migration problem...
* Thus wrote Jake McHenry ([EMAIL PROTECTED]): -Original Message- From: Chris Shiflett [mailto:[EMAIL PROTECTED] --- Jake McHenry [EMAIL PROTECTED] wrote: $result = mysql_query(SELECT * FROM `users` WHERE `uname` = '.$_POST['username'].'); select * from users where uname = '{$_POST['username']}' Is there any advantage to the curly brackets over the '..'? 50% readability. 50% personal prefernce. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Session migration problem...
--- Jake McHenry [EMAIL PROTECTED] wrote: Is there any advantage to the curly brackets over the '..'? There's not enough difference between the two to choose one over the other based on performance, if that's what you mean. Personally, I find that concatenation looks clearer in some cases, and interpolation looks clearer in others. This is just a personal preference thing. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Session migration problem...
* Thus wrote Chris Shiflett ([EMAIL PROTECTED]): --- Jake McHenry [EMAIL PROTECTED] wrote: Is there any advantage to the curly brackets over the '..'? There's not enough difference between the two to choose one over the other based on performance, if that's what you mean. Personally, I find that concatenation looks clearer in some cases, and interpolation looks clearer in others. This is just a personal preference thing. Also depends on how you're editor highlights things (not to start a thread on this.) I tend to use the concate method because I'm used to programming in php the old school method. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php