Hello. I'm using mysql and php for registration on my web-site. Registration is ok. Mysql do queries immediately. But in login there strange things begin to happen. I insert a test in my php code to insert test row to database. First test code inserted immediately, but 2nd was inserted after series of refresh and relog actions only after 10 minutes. The 3rd test query is the same-after approximately 10 minutes after 2nd query.
Here is login code:
<?php
session_start();
if(isset($_SESSION['id'])){
echo 'You have logged in.';
echo $_SESSION['id'];
}
else {
$email=$_POST['email'];
$password=$_POST['password'];
$db=new mysqli('','','','');
if (mysqli_connect_errno()) {
echo 'Unable to connect to database: '.mysqli_connect_error().'. Please e- mail our system administrator. We will fix this error as soon as possible. Thanks for patience and understanding. ';
exit();
}
//TEST QUERY
$query="insert into test values(3, 'test')";
$result=$db->query($query);
//LOGIN QUERY
$query="select id from users where email='$email' and password='$password'";
$result=$db->query($query);
if ($result->num_rows==0) {
echo 'Incorrect email or password.';
}
else {
$row=$result->fetch_assoc();
$_SESSION['id']=$row['id'];
echo 'You have logged in.';
echo $_SESSION['id'];
//THIS TEST QUERY IS NOT IMPLEMENTED
$query="insert into test values(1, test)";
$result=$db->query($query);
}
}
?>
Where is mistake?
Test table consists of 2 columns: id (medium int, primary key, unsigned) and test(text)
Thanks in advance.