Jump to content

Recommended Posts

i get a message saying that the login worked, but it didnt.. what did i do wrong?

<?php
$con = mysql_connect("mysql3.freehostia.com","****BLAH****","****BLAH****");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("****BLAH****", $con);
  
$result = mysql_query("SELECT * FROM account");

$allGood = false;

while($row = mysql_fetch_array($result))
  {
   if ((strnatcasecmp($row['UserName'],$_POST["name"]))==0)
   {
     if ($row['Password']==$_POST["pw"])
       {
   $allGood=true;
   setcookie("user", $_POST["name"], time()+3600);
       }
   }
  }
  ?>

<HTML>
<HEAD>
<TITLE><?php include("titlebar.php"); ?></TITLE>
<link rel="stylesheet" type="text/css" href="template/blue/blue.css">
</HEAD>
<BODY>
<DIV id=mpage>
<DIV id=head><?php include("title.php"); ?></DIV>
<DIV id=nav><?php include("links.php"); ?></DIV>
<DIV id=page>

<DIV id=title>Log In</DIV>
<DIV id=main>
<?php
if  ($_POST["name"]!=''&&!$allGood)
echo 'Problem loging in. please check to make sure that you are using the corect username and password then try again';

if  (!$allGood)
{
echo    '<form action="login.php" method="post">
	<table>
	<tr><td>User Name:</td><td><input type="text" name="name" /></td></tr>
	<tr><td>Password:</td><td><input type="password" name="pw" /></td></tr>
	</table><input type="submit" value="Submit" /> <input type="reset" value="Clear"/>
	</form>';
}
else if ($allGood)
echo 'welcome ' . $_COOKIE["user"];
else echo 'ERROR';
  ?>
</div>
</DIV>
<DIV id=foot><?php include("foot.php"); ?></DIV>
</DIV>

</BODY></HTML>

oh if it helps any my site is http://michaelscorner.freehostia.com

Link to comment
https://forums.phpfreaks.com/topic/68548-usernames-loging-in/
Share on other sites

u have it a bit messy. Normaly i would do it:

 

<?php
$user = $_POST['username'];
$pass = sha1($_POST['pw']);
$allgood = false;
$results = mysql_query("SELECT * FROM account WHERE username='$user'");
$numRows = mysql_num_rows($results);
if($numRows == 1){
     $values = mysql_fetch_array($results);
     if($values['password'] == $pass){
          $allgood = true;
     }
}
?>

 

Also note the sha1() part. Do u have passwords hashed with sha1() or md5() in your database? If so u need to convert the post password to sha1() or md5().

Link to comment
https://forums.phpfreaks.com/topic/68548-usernames-loging-in/#findComment-344596
Share on other sites

The setcookie() code is alright and such is the way ure calling it with $_COOKIE. Dont know whats happening to your part. Also consider my sample code as instead of running a loop through all the records (as u did it with your code) u'll just recieve one single record, making your code a bit faster.

Link to comment
https://forums.phpfreaks.com/topic/68548-usernames-loging-in/#findComment-344613
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.