Trying to understand how to process a form in php that logs in. It seems clumsy, hopefully there is a better way.
Let's say the user login is userid and password. If they enter the information on the form, I jump to the next page:
<?php
if (isset($_POST["id"])) {
$con=mysqli_connect("localhost","user","pw","db");
$codeFile = $_POST["filename"];
$id = $_POST["id"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$res = mysqli_query($con, "SELECT COUNT(*) from users where id='$id' and fname='$fname' and lname='$lname'");
$row = mysqli_fetch_array($res);
$count = $row[1];
if ($count == 1) {
header("submit.php");
die();
}
$res = $con->query('INSERT INTO log values ($id, now(), $codeFile)');
}
?>
The above code should theoretically only jump to submit.php if exactly one row comes back because there is a matching user. It does not seem to work.
how do I request the first column back? It has no name because it is not a named column.
I cannot believe how many statements it takes to get one simple query done, is there any better way in PHP? Java servlets has some nifty shortcuts such as an integer return code with the number of affected lines, among other things.
if this works, I want to do an insert. It would of course be better to do a combined statement and base the test on the number of lines inserted (1 or 0)
$res = $con->query('INSERT INTO log values ($id, now(), $codeFile)');
Is there any way of combining this into a single query that returns true if it succeeds?