Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Serious programming problem

Name: Anonymous 2011-09-21 3:13

Why does my code not work when the username does not exist? When the username doesn't exist it just gives me a blank screen. No error messages, no form, no nothing. It works as intended when the username is found but the password is incorrect and when the username/password are both correct.

Also, please don't make fun of my code. I'm sensitive and I'd like to stay that way.


<?php
$num_rows = 0;
if($_SERVER['REQUEST_METHOD'] == 'POST') {
  $uname = $_POST['username'];
  $pword = $_POST['password'];


$db_handle = mysql_connect(localhost, "admin", "1admin");
$db_found = mysql_select_db("users", $db_handle);

$result = mysql_query("SELECT * FROM logininfo WHERE username = '$uname'") or die(mysql_error());
$num_rows = mysql_num_rows($result) or die(mysql_error());;
if($num_rows > 0)
  $row = mysql_fetch_array($result) or die(mysql_error());

if($num_rows == 0) {
  echo "Username not found.";
}
else if(md5($pword) != $row['password']) {
  echo "Incorrect Password.";
}
else {
  session_start();
  echo "Success.";
  $_SESSION['login'] = "1";
  $_SESSION['username'] = $uname;
  echo '<META HTTP-EQUIV="Refresh" Content="3; URL=index.php">';   
  exit; 
}
}
?>


<FORM NAME ="form1" METHOD ="POST" ACTION ="login.php">

Username: <INPUT TYPE = 'TEXT' Name ='username'  value="<?PHP print $uname;?>" maxlength="20">
Password: <INPUT TYPE = 'TEXT' Name ='password'  value="<?PHP print $pword;?>" maxlength="16">

<P>
<INPUT TYPE = "Submit" Name = "Submit1"  VALUE = "Login">


</FORM>

Name: Anonymous 2011-09-21 17:28

>>19
There are alternatives, but you can get PHP+MySQL hosting anywhere. This is because PHP has been the "amateur standard" for years.

This is also why you are finding tutorials that still use mysql_* functions. From now on, if you see that, close the tab. Those websites are going to teach you very bad form.

Take a look at this: http://framework.zend.com/manual/en/coding-standard.coding-style.html It's a good starting guide for writing legible and maintainable code. Just ignore the part about needing to document everything with /** @stuff_like_this */.

Also, I suggest you don't require your users to create an account with you, especially as a beginning programmer (but also in general). You're going to make a big mistake, and it's going to suck losing all of those millions in court. Instead, try to work with the different public identification sources you can use: OpenID, Facebook, etc.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List