php - Uncaught Error Function Name Must be a String, Log-in Form
Get the solution ↓↓↓As the title says im having a problem with a login form, im trying to make a simple one for a homework, however that error shows up after filling the forms and comparing them with the database, here is the form:
<html>
<head>
<title>Log-in</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h1>Log-in</h1>
</div>
<form method="post" action="connect.php">
<table>
<tr>
<td>Nombre de Usuario:</td>
<td><input type="text" name="username" class="textInput"></td>
</tr>
<tr>
<td>Contraseña:</td>
<td><input type="password" name="password" class="textInput"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="register_btn" class="Register"></td>
</tr>
</table>
</form>
</body>
</html>
and here is the connection to the database:
session_start();
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "registro";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if(!$conn){
die("No hay conexion: ".mysqli_connect_error());
}
$username = $_POST('username');
$password = $_POST('password');
$query = mysqli_query($conn, "SELECT * FROM users where
username = '$username' and password = '$password'");
$nr = mysqli_num_rows($query);
if($nr == 1){
echo "Bienvenido: ".$nombre;
}else if($nr == 0){
echo "No Ingreso";
}
?>
Honestly im a rookie at php and html, but im aware that the "$username" has to be a string in order to work, i tried using "strval" to convert it with no result.
edit: forgot to put the error message:
Fatal error: Uncaught Error: Function name must be a string in connect.php:15 Stack trace: #0 {main} thrown in connect.php on line 15
Answer
Solution:
Solution Here !!!
// Replace and work
$username = $_POST['username'];
$password = $_POST['password'];
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot use isset() on the result of an expression (you can use "null !== expression" instead)
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.