<?php
function ee($a)
{
    if ($_GET == true) {
      if (isset($_GET['debug']) ) {
    }
        echo "\n<br>$a";
    }
}
$link=mysqli_connect('147.32.164.26','alik','*****','alik')
 or die('Error: '.mysqli_error($link));
ee(1);
$result=mysqli_query($link,"SELECT id FROM people WHERE login='".$_POST['login'].
                      "' AND pwd='".$_POST['pwd']."';");
ee(2);
if ($result) {  //we have value, so test, if it is a valid user...
$row=mysqli_fetch_assoc($result);
ee(3);
if ($row["id"]>0){  //yes, if "id" is bigger then zero, it is a valid user 
$id_z=$row["id"];
ee(4);
$id_a = $_POST['car'];
if ($id_a > 0)
{
ee(5);
$result=mysqli_query($link,'INSERT INTO rent (id_z,id_a,rfrom) VALUES ("'
                      .$id_z.'", "'.$id_a.'", CURDATE());');
if (!$result)
  {    ee(-6);
  echo('<br>Could not write into table "rent", with message: ' . mysql_error());
  } else {  ee(6);
$result=mysqli_query($link,'UPDATE cars SET who="'.$id_z.'" WHERE id="'.$id_a.'";');
if (!$result)
  {  ee(-7);
  echo('<br>Could not write into table "cars", with message: ' . mysql_error());
  }  else   {   ee(7);
      echo "<br>One line added OK, debug info: z=$id_z, a=$id_a"; 
    // there should be link back to the main menu passing hidden variables, if any
} }

} else {echo "internal error of our script while decoding car selection";}
} else {echo "internal error of our script while decoding user";}
} else {
  echo "Error accessing database. Please, ";
  echo "<a href=index.htm>login again</a>";
     }

mysqli_close($link); 
?>