Try this
<?php
// check for errors
error_reporting(E_ALL);
ini_set('display_errors', True);
// deny access if not logged
if (!session_id()) session_start();
if (!$_SESSION['logon']){
header("Location:login.php");
die();
}
$username = $_POST['username']; //martin
$password = $_POST['password']; //123456
if (isset($_POST['username']))
{
// connect to server
$con = mysql_connect("localhost", "root", "");
if(!$con){
die('Could not connect: '. mysql_error());}
mysql_select_db("test", $con);
if(mysql_num_rows(mysql_query("SELECT * FROM users where username="$username" AND password = '$password'")))
{
//Correct information
$sql = "SELECT * FROM users where username="$username" AND password = '$password'";
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while($row = mysql_fetch_array($result))
{
$expire = time()+60*60*24*30;//1 month
setcookie("id", $row['id'], $expire);
}
mysql_close($con);
}
}
?>
4
solved Tracing a syntax error in my PHP code [closed]