php - Comparing two inputs with database data: error -


I am trying to compare two input values ​​with two values ​​from the same line from a MySQL table. But I always get an error message what's wrong with this code? (It worked just fine with one input)

  // Check connection (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error (); } // Escape Variable for Security $ numero_cedula = mysqli_real_escape_string ($ conn, $ _POST ['numero_cedula']); $ Codigo = mysqli_real_escape_string ($ cu, $ _POST ['codigo']); $ Sql1 = "Selection number from CDULA test where number codula = $ numero_cedula and chev = $ codigo"; $ ObjGet = mysqli_query ($ conn, $ sql1); If (mysqli_num_rows ($ objGet)) gt; {Echo "duplicate"; } Else {resonant "not a duplicate"; Although the spaces in the column names are allowed in the SQL, for this reason (<< code>   

In your case < / Em>) because there is a place in the column name Numero Cedula :

  v - space v - space $ sql1 = "Select the sample where Numerar Sedula = $ Numero_cedula and chew = $ codigo "by exam  

When wrapping the column name in the backticks, change to the following:

  $ sql1 = "Select Numeror Sedula" test where 'Numero Sedula' = $ Numero_cedula and chew = $ codigo ";  

Plus, make sure that both the $ numero_cedula and $ codigo are integers, and that your columns are also int Type

If they are not, then both of them will need to be wrapped in quotes.

Ie:

  $ sql1 = "Examine 'Nemerro Sedula' where 'numero cedula' = '$ numero_cedula' and select chess = 'codigo'; < / Code> 

Add or die (mysqli_error ($ con)) to mysqli_query () which will show an error in SQL.

< Ul>
  • You can change the name of the column in your database Numero_Cedula underscore.
  • Sidenote: < / Em>

    You have written: "It worked just fine with one input" .

    Will need and your table has two different columns like Numero and Cedula or a Numero Cedula . < However, using this method is subject to it

    An Insight:

    Also make sure your form elements are named.

    Ie: name = "numero_cedula" and name = "codigo"

    add a reporting error at the top of your file) that will help in finding errors.

      error_reporting (E_ALL); Ini_set ('display_errors', 1);  

    SidNote: Error reporting should only be done in staging, and never for production.


    Comments

    Popular posts from this blog

    winforms - C# Form - Property Change -

    java - Messages from .properties file do not display UTF-8 characters -

    javascript - amcharts makechart not working -