Re: [PHP] Help with msql_fetch_array() FIXED ! Now cookie problems :(
Hello again, I got the fetch_array problems fixed. I was using the actual server name, when I switched back to localhost everything worked!! Now I have a question about how to make cookies work on a Windows machine. This is what I have these parameters set to but it's not working. Do I have slashes/backslashes wrong, or is there something else I have to do in Apache??: session.save_path = C:/Program Files/Apache Group/Apache/web/php/dir/files/temp ; Whether to use cookies. session.use_cookies = 1 ; Name of the session (used as cookie name). session.name = PHPSESSID ; Initialize session on request startup. session.auto_start = 0 ; Lifetime in seconds of cookie or, if 0, until browser is restarted. session.cookie_lifetime = 0 ; The path for which the cookie is valid. session.cookie_path = c:/Program Files/Apache Group/Apache/web/php/dir/files/temp ; The domain for which the cookie is valid. session.cookie_domain = www.mydomain.com As always, thanks for your help. PHPCoder [EMAIL PROTECTED] 07/24/02 01:50 PM To: Matthew Bielecki [EMAIL PROTECTED] cc: php-general [EMAIL PROTECTED] Subject:Re: [PHP] Help with msql_fetch_array() I can almost guarantee that it's not the second line that is failing, the problem here is that $result is not containing naything, and that is normally due to the fact that you are not connecting to the db, or the table tablename is not there. I use the following format as my standard MySQL connect and query snippet: $link = @mysql_connect(localhost,$username,$password) or die ('Could not connect!'); //@ suppresses the default error message generated by this function and the or die() bit kills the script right then and there should it not be able to connect. mysql_select_db(YOUR_DB_NAME,$link); $sql = select * from your_table_name; if ( $result = mysql_query($sql)) { // checks to see if $result contains anything before it even tries to fetch an associative array from it. $row = mysql_fetch_assoc($result); } else { echo Empty result set!; Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 out of 10 times, you don't need the array element id's that is returned by mysql_fetch_array. Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!!
Re: [PHP] Help with msql_fetch_array() FIXED ! Now cookie problems:(
On Thu, 25 Jul 2002, Matthew Bielecki wrote: session.save_path = C:/Program Files/Apache Group/Apache/web/php/dir/files/temp Considering using something like: c:/temp, sure beats typing and remembering that path :) How are you setting the cookie in the code? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] Help with msql_fetch_array() FIXED ! Now cookie problems :(
Hello Matthew, Thursday, July 25, 2002, 5:06:09 PM, you wrote: MB Hello again, MB I got the fetch_array problems fixed. I was using the actual server name, MB when I switched back to localhost everything worked!! MB Now I have a question about how to make cookies work on a Windows machine. MB This is what I have these parameters set to but it's not working. Do I MB have slashes/backslashes wrong, or is there something else I have to do in MB Apache??: MB session.save_path = C:/Program Files/Apache MB Group/Apache/web/php/dir/files/temp MB ; Whether to use cookies. MB session.use_cookies = 1 MB ; Name of the session (used as cookie name). MB session.name = PHPSESSID MB ; Initialize session on request startup. MB session.auto_start = 0 MB ; Lifetime in seconds of cookie or, if 0, until browser is restarted. MB session.cookie_lifetime = 0 MB ; The path for which the cookie is valid. MB session.cookie_path = c:/Program Files/Apache MB Group/Apache/web/php/dir/files/temp MB ; The domain for which the cookie is valid. MB session.cookie_domain = www.mydomain.com try something like this session.save_path = c:/Program Files/Apache Group/Apache/web/php/dir/files/temp i mean without ... i had that problem - deleted and all is working now -- Best regards, Alexander Kuznetsov -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] Help with msql_fetch_array() FIXED ! Now cookie problems:(
OH MY GOSH...I ACTUALLY GOT A REAL PROGRAM TO RUN! Thanks a ton x 1,000,000 Alexander Thanks, Matthew J. Bielecki, MCP, A+ Certified Technician Hobart Corporation Field Engineer - Weighing Network Systems Phone (937) 332-7163Fax (937) 332-3222 Email [EMAIL PROTECTED] Alexander Kuznetsov [EMAIL PROTECTED] 07/25/02 10:15 AM Please respond to Alexander Kuznetsov To: Matthew Bielecki [EMAIL PROTECTED] cc: php-general [EMAIL PROTECTED] Subject:Re[2]: [PHP] Help with msql_fetch_array() FIXED ! Now cookie problems :( Hello Matthew, Thursday, July 25, 2002, 5:06:09 PM, you wrote: MB Hello again, MB I got the fetch_array problems fixed. I was using the actual server name, MB when I switched back to localhost everything worked!! MB Now I have a question about how to make cookies work on a Windows machine. MB This is what I have these parameters set to but it's not working. Do I MB have slashes/backslashes wrong, or is there something else I have to do in MB Apache??: MB session.save_path = C:/Program Files/Apache MB Group/Apache/web/php/dir/files/temp MB ; Whether to use cookies. MB session.use_cookies = 1 MB ; Name of the session (used as cookie name). MB session.name = PHPSESSID MB ; Initialize session on request startup. MB session.auto_start = 0 MB ; Lifetime in seconds of cookie or, if 0, until browser is restarted. MB session.cookie_lifetime = 0 MB ; The path for which the cookie is valid. MB session.cookie_path = c:/Program Files/Apache MB Group/Apache/web/php/dir/files/temp MB ; The domain for which the cookie is valid. MB session.cookie_domain = www.mydomain.com try something like this session.save_path = c:/Program Files/Apache Group/Apache/web/php/dir/files/temp i mean without ... i had that problem - deleted and all is working now -- Best regards, Alexander Kuznetsov
[PHP] Help with msql_fetch_array()
I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!!
Re: [PHP] Help with msql_fetch_array()
I can almost guarantee that it's not the second line that is failing, the problem here is that $result is not containing naything, and that is normally due to the fact that you are not connecting to the db, or the table tablename is not there. I use the following format as my standard MySQL connect and query snippet: $link = mysql_connect(localhost,$username,$password) or die ('Could not connect!'); // suppresses the default error message generated by this function and the or die() bit kills the script right then and there should it not be able to connect. mysql_select_db(YOUR_DB_NAME,$link); $sql = select * from your_table_name; if ( $result = mysql_query($sql)) { // checks to see if $result contains anything before it even tries to fetch an associative array from it. $row = mysql_fetch_assoc($result); } else { echo Empty result set!; Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 out of 10 times, you don't need the array element id's that is returned by mysql_fetch_array. Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with msql_fetch_array()
Try using mysql_query(); instead of mysql_db_query(); The SQL query is the first parameter in this function. The second parameter is a pointer connecting to the mysql server. The pointer is generated by mysql_connect() and you'll also need to select the database with mysql_select_db(). But it's the standard way.. $db = mysql_connect(localhost, username, password);// connect to mysql server mysql_select_db(mytable, $db); // select database by name $query = SELECT * FROM mytable ORDER BY id; // define query to submit $result = mysql_query($query, $db); // submit query if (mysql_num_rows($result) 0) // skip if no rows were found { while ($row = mysql_fetch_array($result)) { // .. do whtever.. } } mysql_close($db); It's also a common practice to put the first couple of lines in a file to include() back into your main script so that you can protect your useranme and password. Good luck. -Kevin - Original Message - From: Matthew Bielecki [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 24, 2002 10:34 AM Subject: [PHP] Help with msql_fetch_array() I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with msql_fetch_array()
You beat me too the punch and I think you explained it better than me, but just one minor little thing to note. Where you said.. if ( $result = mysql_query($sql)) This is not a valid way to check if the query has returned anything. mysql_query() returns FALSE on error. So if there was no error but there also wasn't anything returned then the object stored in $result wiill more than likely evaluate to TRUE. For the determining factor you should count the number of rows with mysql_num_rows($result). If the returned value is zero then you know it hasn't returned anything. -Kevin - Original Message - From: PHPCoder [EMAIL PROTECTED] To: Matthew Bielecki [EMAIL PROTECTED] Cc: php-general [EMAIL PROTECTED] Sent: Wednesday, July 24, 2002 11:50 AM Subject: Re: [PHP] Help with msql_fetch_array() I can almost guarantee that it's not the second line that is failing, the problem here is that $result is not containing naything, and that is normally due to the fact that you are not connecting to the db, or the table tablename is not there. I use the following format as my standard MySQL connect and query snippet: $link = @mysql_connect(localhost,$username,$password) or die ('Could not connect!'); //@ suppresses the default error message generated by this function and the or die() bit kills the script right then and there should it not be able to connect. mysql_select_db(YOUR_DB_NAME,$link); $sql = select * from your_table_name; if ( $result = mysql_query($sql)) { // checks to see if $result contains anything before it even tries to fetch an associative array from it. $row = mysql_fetch_assoc($result); } else { echo Empty result set!; Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 out of 10 times, you don't need the array element id's that is returned by mysql_fetch_array. Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with msql_fetch_array()
Yes, what on earth was I thinking! should be: ... $result = mysql_query($sql); if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); } else { echo whatever; } ... Kevin Stone wrote: You beat me too the punch and I think you explained it better than me, but just one minor little thing to note. Where you said.. if ( $result = mysql_query($sql)) This is not a valid way to check if the query has returned anything. mysql_query() returns FALSE on error. So if there was no error but there also wasn't anything returned then the object stored in $result wiill more than likely evaluate to TRUE. For the determining factor you should count the number of rows with mysql_num_rows($result). If the returned value is zero then you know it hasn't returned anything. -Kevin - Original Message - From: PHPCoder [EMAIL PROTECTED] To: Matthew Bielecki [EMAIL PROTECTED] Cc: php-general [EMAIL PROTECTED] Sent: Wednesday, July 24, 2002 11:50 AM Subject: Re: [PHP] Help with msql_fetch_array() I can almost guarantee that it's not the second line that is failing, the problem here is that $result is not containing naything, and that is normally due to the fact that you are not connecting to the db, or the table tablename is not there. I use the following format as my standard MySQL connect and query snippet: $link = @mysql_connect(localhost,$username,$password) or die ('Could not connect!'); //@ suppresses the default error message generated by this function and the or die() bit kills the script right then and there should it not be able to connect. mysql_select_db(YOUR_DB_NAME,$link); $sql = select * from your_table_name; if ( $result = mysql_query($sql)) { // checks to see if $result contains anything before it even tries to fetch an associative array from it. $row = mysql_fetch_assoc($result); } else { echo Empty result set!; Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 out of 10 times, you don't need the array element id's that is returned by mysql_fetch_array. Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with msql_fetch_array()
Shouldn't it be: $result = mysql_query($sql, $link_id); PHP will be quick to tell you that there is a missing link identifier in the mysql_query() call. It's happened to me plenty of times. HTH! Martin Clifford Homepage: http://www.completesource.net Developer's Forums: http://www.completesource.net/forums/ PHPCoder [EMAIL PROTECTED] 07/24/02 02:16PM Yes, what on earth was I thinking! should be: ... $result = mysql_query($sql); if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); } else { echo whatever; } ... Kevin Stone wrote: You beat me too the punch and I think you explained it better than me, but just one minor little thing to note. Where you said.. if ( $result = mysql_query($sql)) This is not a valid way to check if the query has returned anything. mysql_query() returns FALSE on error. So if there was no error but there also wasn't anything returned then the object stored in $result wiill more than likely evaluate to TRUE. For the determining factor you should count the number of rows with mysql_num_rows($result). If the returned value is zero then you know it hasn't returned anything. -Kevin - Original Message - From: PHPCoder [EMAIL PROTECTED] To: Matthew Bielecki [EMAIL PROTECTED] Cc: php-general [EMAIL PROTECTED] Sent: Wednesday, July 24, 2002 11:50 AM Subject: Re: [PHP] Help with msql_fetch_array() I can almost guarantee that it's not the second line that is failing, the problem here is that $result is not containing naything, and that is normally due to the fact that you are not connecting to the db, or the table tablename is not there. I use the following format as my standard MySQL connect and query snippet: $link = @mysql_connect(localhost,$username,$password) or die ('Could not connect!'); //@ suppresses the default error message generated by this function and the or die() bit kills the script right then and there should it not be able to connect. mysql_select_db(YOUR_DB_NAME,$link); $sql = select * from your_table_name; if ( $result = mysql_query($sql)) { // checks to see if $result contains anything before it even tries to fetch an associative array from it. $row = mysql_fetch_assoc($result); } else { echo Empty result set!; Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 out of 10 times, you don't need the array element id's that is returned by mysql_fetch_array. Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with msql_fetch_array()
At 11:26 AM 7/24/2002 Wednesday, Martin Clifford wrote: Shouldn't it be: $result = mysql_query($sql, $link_id); Actually mysql_query should default to the last database connection opened if no link identifier has been specified. So the link identifier to not absolutely required. Phillip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with msql_fetch_array()
On Thursday 25 July 2002 00:34, Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); It's a very good idea to add some error checking code it'll save you a lot of grief. See examples in manual for details. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Nine years of ballet, asshole. -- Shelly Long, to the bad guy after making a jump over a gorge that he couldn't quite, in Outrageous Fortune */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with msql_fetch_array()
Well I think you were correct about not connecting to the db, but I don't understand why. I wrote another little script just to test the connection. ?php $link = mysql_connect(servername,username,password) or die(Couldn't make connection.); $diditwork = mysql_select_db(news, $link); if ($diditwork FALSE) { echo got the db..yea!; echo $link; } else { echo didnt get db...bo; echo $link; } ? This returns didnt get db...booResource id #1 I don't understand how I can get a resource ID but then not be able to use the news database. Like I described earlier, this happens with my other db as well. I can connect to the db through the console or any other client I have on the physical server and do whatever I want with the db's, I'm just having problems with php. Thanks again for your help!! PHPCoder [EMAIL PROTECTED] 07/24/02 01:50 PM To: Matthew Bielecki [EMAIL PROTECTED] cc: php-general [EMAIL PROTECTED] Subject:Re: [PHP] Help with msql_fetch_array() I can almost guarantee that it's not the second line that is failing, the problem here is that $result is not containing naything, and that is normally due to the fact that you are not connecting to the db, or the table tablename is not there. I use the following format as my standard MySQL connect and query snippet: $link = @mysql_connect(localhost,$username,$password) or die ('Could not connect!'); //@ suppresses the default error message generated by this function and the or die() bit kills the script right then and there should it not be able to connect. mysql_select_db(YOUR_DB_NAME,$link); $sql = select * from your_table_name; if ( $result = mysql_query($sql)) { // checks to see if $result contains anything before it even tries to fetch an associative array from it. $row = mysql_fetch_assoc($result); } else { echo Empty result set!; Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 out of 10 times, you don't need the array element id's that is returned by mysql_fetch_array. Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!!
Re: [PHP] Help with msql_fetch_array()
That should definitely be working. Only thing I can think of is that you're database name isn't correct. You're certain news is the full name of the database.. I mean it's not news_com or something like that? The $link must be valid becuase the script isn't ending with Couldn't make connection. So that just leaves the mysql_select_db() function. And the only thing that will make that function return FALSE is if it can't find the database name for that user on the specified server. -Kevin - Original Message - From: Matthew Bielecki [EMAIL PROTECTED] To: PHPCoder [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: php-general [EMAIL PROTECTED] Sent: Wednesday, July 24, 2002 2:07 PM Subject: Re: [PHP] Help with msql_fetch_array() Well I think you were correct about not connecting to the db, but I don't understand why. I wrote another little script just to test the connection. ?php $link = mysql_connect(servername,username,password) or die(Couldn't make connection.); $diditwork = mysql_select_db(news, $link); if ($diditwork FALSE) { echo got the db..yea!; echo $link; } else { echo didnt get db...bo; echo $link; } ? This returns didnt get db...booResource id #1 I don't understand how I can get a resource ID but then not be able to use the news database. Like I described earlier, this happens with my other db as well. I can connect to the db through the console or any other client I have on the physical server and do whatever I want with the db's, I'm just having problems with php. Thanks again for your help!! PHPCoder [EMAIL PROTECTED] 07/24/02 01:50 PM To: Matthew Bielecki [EMAIL PROTECTED] cc: php-general [EMAIL PROTECTED] Subject:Re: [PHP] Help with msql_fetch_array() I can almost guarantee that it's not the second line that is failing, the problem here is that $result is not containing naything, and that is normally due to the fact that you are not connecting to the db, or the table tablename is not there. I use the following format as my standard MySQL connect and query snippet: $link = @mysql_connect(localhost,$username,$password) or die ('Could not connect!'); //@ suppresses the default error message generated by this function and the or die() bit kills the script right then and there should it not be able to connect. mysql_select_db(YOUR_DB_NAME,$link); $sql = select * from your_table_name; if ( $result = mysql_query($sql)) { // checks to see if $result contains anything before it even tries to fetch an associative array from it. $row = mysql_fetch_assoc($result); } else { echo Empty result set!; Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 out of 10 times, you don't need the array element id's that is returned by mysql_fetch_array. Matthew Bielecki wrote: I have a couple of scripts that fail with the error of: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in... I'm new to both SQL and PHP and I'm wondering if I have some setting turned off or what. Here's the piece of code that is failing (the second line fails): $result = mysql_db_query($dbname, SELECT * FROM tablename ORDER BY id); $row = mysql_fetch_array($result); Thanks for your help in advance!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php