Originally Posted by moisesbr
I have a database where some students don't have their Identity_number stored , but all students have a code.
I am trying to implement a search in this database with some degree of safety.
In first html page, both fields are mandatory (because everbody has an Identity_number to type )
$result = mysql_query("SELECT * FROM certificado WHERE Identity_number= '$cpf'") or die (mysql_error());
If found Identity_number, compare certificado.code with $code and show (html result - a already have) if match.
However if Identity_number is not found, then search only by code. ( because nobody will guess student does not have Identity_number in database .)
Is it easy to do such a code ? I need help at least with $result mysql lines.
The standard mysql functions in PHP are on the way out, so you should write this with either PDO
instead. It is also advisable to use "prepared statements" for the query (we can dig into this part later, feel free to look it up in the meantime).
Do you expect to have more than one row returned from such a query? Or will each student only have one row in the table (i.e. is "Identity_number" set up with the "unique" constraint in the table)?