Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 30th, 2005, 4:11 PM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
The principle behind the suggestion is that for robust code you need to keep all warnings and errors enabled and turned up full volume, so to speak. That helps catch the inevitable bugs you will have in your code. When you go to production, you suppress/reroute by catching the errors and either logging them or emailing them to yourself, but keep them from sight of the user. Any fatal errors, of course, should be made known to the user in general terms. Do not give specific details of an error to the user -- he/she might be malicious and able to intuit a weak point of penetration if you do so.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 30th, 2005, 7:27 PM   #12
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
function check_login_info($username, $password)
	{
		$user_exists = false;
		$dbcon = db_connect();
		$selected = mysql_select_db("users", $dbcon);
		$userresult = mysql_query("SELECT username FROM users");
                #################
		while ($userrow = mysql_fetch_array($userresult, MYSQL_ASSOC))
		{
			if ($userrow['username'] == $username)
				$user_exists = true;
		}
		if (!$user_exists)
		{
			die ("That user doesn't exist.");
		}
		$result = mysql_query("SELECT password FROM users WHERE username='".$username."'", $dbcon);
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		if (md5($password) == md5($row['password']))
		{
			return login_user();
		} else {
			return false;
		}
		mysql_free_result($result);
		mysql_close($dbcon);
	}

im trying to do that and here's the warning im getting:

Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/infrec/public_html/infrec/login_result.php on line 17
line 17 is the one right under all the #s
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Jul 30th, 2005, 7:42 PM   #13
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Test the success of the query before you try to use the result in subsequent operations. If the query failed you won't have something you can fetch an array from. If you use the query error message you'll normally get an informative guide.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 30th, 2005, 10:14 PM   #14
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
How do I test the success of the query? The only thing i can think of is to use mysql_fetch_assoc() to print it but of course that won't work...
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Jul 30th, 2005, 10:27 PM   #15
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
Originally Posted by PHP manual
For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
Here's an example of exiting on failure, with the SQL error message:
$catalog = mysql_query ($queryProducts) or die (mysql_error());
One could also test for false and take some other action. Printing out the actual mysql error is a good idea, particularly during the development phase.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 31st, 2005, 9:29 PM   #16
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
ok it says "No database selected" and im like "god im dumb". after i connect:

$dbcon = mysql_connect($dbhost, $dbusername, $dbpassword);

how do i select the db? and then how do i select the table for the query to operate on?
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Jul 31st, 2005, 10:17 PM   #17
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
mysql_select_db ($database) or die (mysql_error());

after that, "Select whatever from whosis", whatever is the column (field), whosis is the table. Keep the PHP manual handy on a link or a tab. It's invaluable. Just search for the function name to get the parameters and return.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 1st, 2005, 4:59 PM   #18
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
now it says this:

Quote:
Access denied for user: 'infrec_user@localhost' to database 'Resource id #2'
i know ill have to bother the hosting people with this one. but does anyone know what it means by 'Resource id #2'? thanks.
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Aug 1st, 2005, 6:21 PM   #19
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It sounds like you have two connections to the same DB. You're being denied access to the second connection for whatever reason. Also, if you use the designation, "localhost", mysql will override that and try to connect to a local socket. If you really want that not to happen (want to actually use tcp/ip), use 127.0.0.1. The use of "localhost" coupled with your comment about "the hosting people" confuses me because "localhost" is normally YOUR machine.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 2nd, 2005, 3:29 AM   #20
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
With my hosting i use localhost as well, so its with regards to the machine hosting the webpage.

This is also due to the fact i can if i want have remote access to my database but i turn it off, therefore only enabaling it to my web pages and not external ones.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC