Page 2 of 2

Re: PHP coding help!!

Posted: Mon Oct 31, 2011 5:59 am
by social_experiment
Here's the basic process for a login system

1. User accesses a form (that's main_login.php for you)
2. Form is submitted to process page (checklogin.php for you)
3. User is logged in, redirect to logged in page at which login form is no longer needed

Does the current script work i.e let's a user log in?

Re: PHP coding help!!

Posted: Mon Oct 31, 2011 9:51 am
by dsnraju
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?php

if($_POST['Submit'] == "Login")
{
$sel_user = "select * from usertable where username = ".$_POST['myusername']." and password = ".$_POST['mypassword'];

$res_user = mysql_query($sel_user);
$count = mysql_num_rows($res_user);

if($count > 0)
{
echo "<script>";
echo "location.replace('main.php');";
echo "</script>";
}
else
{
echo "<script>";
echo "alert('Wrong Username or Password');";
echo "location.replace('checklogin.php');";
echo "</script>";
}


}

?>


Try this code and solve your problem.

Acoording to this code you need PHP Sessions also.

Re: PHP coding help!!

Posted: Mon Oct 31, 2011 10:40 am
by social_experiment
Yes, very rudimentary but dsnraju has the same idea as i do, your code is probably ok but your login logic is not quite there yet.