MySQL Forums
Forum List  »  PHP

Re: Don't know if the problem is me, mysql or php
Posted by: Peter Brawley
Date: March 10, 2020 01:33PM


I have a 'users' file in the db which holds 4 fields
Id - auto-increment primary key
username - var - unique key
password - var
role - var

It's a table not a file (code is text, words matter).

And to facilitate finding PHP errors & bugs, put this at the top of each script ...

$debug = 1;
ini_set( "display_errors", $debug );

... write an error handler func (in an include file) that writes error info to a log file, and include calls to the err handler in all statements that can fail, eg ...

$link = mysqli_connect(...) or my_err_handler( mysqli_connect_error() );

if( !mysqli_stmt_bind_param(...) ) 
  my_err_handler( mysqli_error($link) );

When it's all production ready, change $debug=1 stmts to $debug=0.

> $sql = "SELECT * FROM `users` WHERE `username`= "$username" and `password`= "$password"";

1 Yikes, you're storing user passwords in raw text? Don't do it, not secure!

2 Re-read the manual page for mysqli_prepare(),
Param placeholders are question marks.

That should get you unstuck.

Options: ReplyQuote

Written By
Re: Don't know if the problem is me, mysql or php
March 10, 2020 01:33PM

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.