Hey there guys, I think I'm just being a spastic, but I do not know what to do anymore, my javascript does not want to work, before the prepared statements are even ran, where the $_GET['action'] is checked, it already throws out my error that the action can't be run. What am I missing.
<?php
require_once 'config.php';
error_reporting(E_ALL);
//Connection to my database
$mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
if(mysqli_connect_errno())
{
printf("Connection failed: %s\n", mysqli_connect_errno());
exit();
}
if($_GET['action'] == 'UserLogin')
{
$stmt = $mysqli->stmt_init();
//prepared statement
if($stmt = $mysqli->prepare("select * from login where username = ? and password = ?"))
{
//bind my parameters
$stmt->bind_param("ss",$username,$password);
$username = $_POST["username"];
$password = $_POST["password"];
//execute query
$stmt->execute();
//bind the result variables
$stmt->bind_result($username,$password);
//Store my values
$stmt->store_result();
//fetch values
if($stmt->fetch())
{
$_SESSION["username"] = $username;
alert("Authenticated");
header("location : Main_menu.php");
exit();
}
else
{
alert("username or password is incorrect");
}
$stmt->close();
$stmt->free_result();
}
else
{
echo "Username or password incorrect";
}
}
else
{
echo "no";
}
$mysqli->close();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<script language = "javascript">
function UserLogin()
{
document.login.submit();
}
</script>
<form name="login" action="login.php?action=UserLogin" method="post">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Radius Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="button" name="Submit" value="Login" onclick="javascript:UserLogin();"/></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</html>