MySQL Forums
Forum List  »  PHP

Re: MIstake in the code?
Posted by: Peter Brawley
Date: January 16, 2018 02:10PM

Syntax errors...

Lines 66 & 72 need terminating semicolons.

Logical errors ...

1. This needs error handling, at the very least ...
$con = new mysqli ($dbServer, $dbUsername, $dbPassword, $dbSchema)
       or exit( mysqli_connect_error() );

2. Select * is inefficient. Query only the expressions needed.

$sql = "SELECT * FROM ProvidersAccounts WHERE `LicenseNumber` = '" .$licenseNumber."' ";

3. This is wrong:
$licenseValid = mysqli_query($con, $sql);

mysqli_query() returns a resource even if the query returns zero rows. Var names should be self-documenting. You need error handling in all Db calls...
$res = mysqli_query($con, $sql) or exit( mysqli_error($con) );

Those problems also occur in the next query.

Re debugging, see http://blog.teamtreehouse.com/how-to-debug-in-php for a nice summary of basic debugging methods.

There are many open-source and commercial PHP debuggers, I've only tried a few of them. Some just offer syntax checks by spawning a PHP run on the file and reporting the syntax errors. Others offer breakpoints &c, eg https://xdebug.org/docs/index.php?action=index.

My preference is to use a general-purpose programmer's editor for all languages I write. I use NotePad++, which can be taught to run PHP on a source file and report syntax errors, and to suss out bugs I add in reporting stubs (eg echo in PHP) to track var values. Chacun à son goût.

Options: ReplyQuote


Subject
Written By
Posted
January 16, 2018 07:46AM
Re: MIstake in the code?
January 16, 2018 02:10PM


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.