Hi,
Change in your form with this:
Username: <input type="text" name="user"/></br>
Password: <input type="text" name="password"/></br>
"name" value and $_POST['value'] must be the same value.
MarPlo
Junior Poster in Training
55 posts since Apr 2012
Reputation Points: 1
Solved Threads: 15
Skill Endorsements: 0
Change the password type attribute:
<form action="login.php" method="post">
<label for = "user">Username: </label><input type="text" name="user" id="user" />
<label for = "password">Password: </label><input type="password" name="password" id="password" /></br>
<input type="submit" name="sublog" value="Login" />
</form>
Your php:
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("logindb", $con);
$user = mysql_real_escape_string($_POST['user']);
$pw = mysql_real_escape_string($_POST['password']);
$sql = "SELECT username, password, email FROM users WHERE username='$user' LIMIT 1";
$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
if (mysql_num_rows($result)){
$data = mysql_fetch_assoc($result);
//IDEALLY you'd hash your pw with a salt - this is not very secure
if($pw == $data['password']){
setcookie("user", $user , time()+3600);
echo "You Have Successfully Logged In<br />";
}
}else{
echo "You Have Failed To Logged In<br />";
}
?>
<a href="/index.php">CLick here To go back Home</a>
diafol
Keep Smiling
10,833 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,533
Skill Endorsements: 61
Try:
echo "<br />Congratulations You have registered And logged in with your account ($cookie)<br />";
Also, you should check for the existence of a superglobal ($_COOKIE) before ascribing it to another var:
$cookie = $_COOKIE["userforcong"];
This will end in tears if $_COOKIE["userforcong"] does not exist.
diafol
Keep Smiling
10,833 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,533
Skill Endorsements: 61
Ah! I was looking at line 5 in the error message - you're problem is at line 25:
function logout()
{
if (isset($_COOKIE["user"]))
{
setcookie("user", "", time()-3600);
echo '</br>Logout Successfully</br>';
}
}
You can't set a cookie once you've echoed stuff to the screen or have got any html/whitespace in the page (http://php.net/manual/en/function.setcookie.php). I'm assuming that your page is included inside another file? This file seems to have output before the include statement. I may be mistaken.
diafol
Keep Smiling
10,833 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,533
Skill Endorsements: 61
diafol
Keep Smiling
10,833 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,533
Skill Endorsements: 61