MySQL Forums
Forum List  »  PHP

Re: php mysql search
Posted by: Peter Brawley
Date: May 20, 2018 10:32AM

Re the code: first, every mysqli API call to the database that can raise an error needs error trapping, eg minimally ...

$connect = mysqli_connect(...) or exit( mysqli_connect_error() );
$result = mysqli_query(...) or exit( mysqli_error($connect) );

And all data harvested from $_GET[] and $_POST[] needs to be sql-injection-proofed with mysqli_escape_string().

Re the query call: there are 4 possible outcomes (i) it errors out (ii) it retrieves one matching row (iii) it finds multiple matching rows, (iv) it finds no matching row. Your code covers only 2 of the 4 possibilities. Code for all possibilities, add a $debug var, set it true till no more bugs are found, insert code to display all relevant variable values so you can track what's happening.

Options: ReplyQuote

Written By
May 20, 2018 09:43AM
Re: php mysql search
May 20, 2018 10:32AM
May 20, 2018 04:21PM
May 24, 2018 05:31PM
May 24, 2018 06:47PM
May 24, 2018 10:12PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.