Page 1 of 1

Need help debugging, ...please

Posted: Mon Jan 30, 2006 9:55 am
by Pesho
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi all, 
I'm almost hopeless that somebody will spot the error, but maybe this forum will help.

The error is: "[b]ERROR - database error[/b]" and it's coming from the following fragment in [b]h_register_funcs.inc[/b]:

Code: Select all

else {
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$password = md5($_POST['password1']);
$user_ip = $_SERVER['REMOTE_ADDR'];
// Create a new hash to insert into the db and the confirmation email
$hash = md5($email.$supersecret_hash_padding);

$query = "INSERT INTO user (user_name, first_name, last_name, password, email, remote_addr, confirm_hash, is_confirmed, date_created)
VALUES ('$user_name', '$first_name', '$last_name', '$password', '$email', '$user_ip', '$hash', 0, NOW())";
$result = mysqli_query($dbh, $query);
if (!$result) {
[b]$feedback = 'ERROR - Database error';[/b]
return $feedback;
}
The strange thing is that my efforts to debug were unsuccessful. I tried the following change:

Code: Select all

$feedback = 'ERROR - Database error'.mysqli_error($dbh);
but it doesn't give a more descriptive error - it stays the same.

if I write:

Code: Select all

$result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));
it totally dies and displays a blank page when calling the function user_register() from h_register.php.

The other thing I can't figure out is why after adding:

Code: Select all

echo $query;
it doesn't display it either.

if it's necessary I can post more code or even everything.

thank you,
pesho


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Jan 30, 2006 10:16 am
by Chris Corbyn
What happens if you change mysqli_query() to mysql_query() ?

Oh, hang on. You have the parameters for mysqli_query() in the wrong order. The query comes before thje resource id ;)

http://php.net/mysql_query

EDIT | Putting error_reporting(E_ALL); at the top of your scripts whilst developing will save you a lot of time :)