I need a login script in PHP and wrote this (see script below) but the form is not sending the variables from the inputfiedls to the same file through the URL (with GET or POST)
<?php
session_start();
$admin=true;
function controle($uname, $pword, $admin){
$datatable = "my_table";
$servername = 'localhost';
$username = 'admin';
$password = '1234';
$database = 'myDB';
//Create connection
$con = mysqli_connect($servername, $username,
$password, $database);
if ($con == false){
die("STATUS: Error: ".mysqli_error_connect());
}
if ($admin == true){
$sql = "SELECT * FROM ".$datatable;
}
$result = mysqli_query($con,$sql);
$rows=mysqli_fetch_assoc($result);
$sql2 = "SELECT COUNT(*) AS total FROM ".$datatable;
$result = mysqli_query($con,$sql2);
$row2 = $result->fetch_row();
$total_records = $row2[0];
if ($total_records > 0){
$gebruikersnaam = $rows['username'];
$wachtwoord = $rows['password'];
if ($pword != $wachtwoord){
return false;
} else {
return $gebruikersnaam;
}
} else {
return false;
}
}
// Check name and password
if (isset($_POST['verzonden'])){
$username = $_POST['username'];
$password = md5($_POST['wachtwoord']);
$login_ok = controle($username, $password, $admin);
if (login_ok != false){
//correct
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
}
}
if (controle($_SESSION['username'],
$_SESSION['wachtwoord'], $admin) == false) {
echo "<form method='post'
action='".$_SERVER['PHP_SELF']."?";
reset($_GET); // put the array pointer to 0 when
starting
// Send the variables again
while($getvar = each($_GET)){
$varName = $getvar['key'];
$varValue = $getvar['value'];
echo "$varName=$varValue&";
}
echo "'><br><br>";
echo "Name: ";
echo "<input type='text' name='username'>";
echo "<br>";
echo "Password: ";
echo "<input type='text' name='wachtwoord'>";
echo "<br>";
echo "<input type='submit' value='log in'
name='verzonden'>";
echo "</form>";
if ($admin == "true"){
echo "<p>-- ADMIN status is vereist!";
}
exit;
}
?>
But it seems that the form does not sending anything.. I was expecting something like :
authentication.php?username=MYNAME&wachtwoord=4321
The connection with my database is ok, I can read the variables from there. I have no id why my form is not sending the variables I got just "authentication.php?"