Although spaces in column names are allowed in SQL, the reason for this (in your case) is because the column name Numero Cedula
contains a space:
v -- space v -- space
$sql1 = "SELECT Numero Cedula FROM Teste WHERE Numero Cedula=$numero_cedula
AND Chave=$codigo";
Change it to the following while wrapping the column name in backticks:
$sql1 = "SELECT `Numero Cedula` FROM Teste WHERE `Numero Cedula`=$numero_cedula
AND Chave=$codigo";
Plus, make sure that both $numero_cedula
and $codigo
are integers, and that your columns are also int
types.
If they are not, then both will need to be wrapped in quotes.
I.e.:
$sql1 = "SELECT `Numero Cedula` FROM Teste WHERE `Numero Cedula`='$numero_cedula'
AND Chave='$codigo'";
Add or die(mysqli_error($con))
to mysqli_query()
which will show you the error in SQL.
- You can also rename the column in your database to
Numero_Cedula
using an underscore.
Sidenote:
You wrote: "It worked fine with just one input".
You will need to elaborate on that and whether your table contains two seperate columns such as Numero
and Cedula
or one Numero Cedula
.
However, using this method is subject to SQL injection. Use prepared statements, or PDO with prepared statements.
An insight:
Also make sure that your form elements are named.
I.e.: name="numero_cedula"
and name="codigo"
Add error reporting to the top of your file(s) which will help find errors.
error_reporting(E_ALL);
ini_set('display_errors', 1);
Sidenote: Error reporting should only be done in staging, and never for production.