![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#12 | |
|
Hobbyist Programmer
|
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:
__________________
Children in the dark cause accidents, and accidents in the dark cause children. http://www.ronincoders.org |
|
|
|
|
|
|
#13 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#14 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#15 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
$catalog = mysql_query ($queryProducts) or die (mysql_error());
__________________
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 |
|
|
|
|
|
|
#16 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#17 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#18 | |
|
Hobbyist Programmer
|
now it says this:
Quote:
__________________
Children in the dark cause accidents, and accidents in the dark cause children. http://www.ronincoders.org |
|
|
|
|
|
|
#19 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#20 |
|
Programming Guru
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|