Jump to content
Larry Ullman's Book Forums

[Error - C9] Registration Form


Recommended Posts

Hello everyone!

 

I did exactly what are instructed in the book to create the registration form, but it always show the following errors:

 

 

 

You could not be registered due to a system error. WE apologize for any inconvenience.

 

Warning: mysqli_error() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\Chapter3\register.php on line55

 

 

Query: INSERT INTO users(first_name,last_name, email, pass, registration_date) VALUES( 'Victor','Hugo','VictorHugo@gmail.com',SHA1('123'),NOW())

 

Warning: mysqli_close() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\Chapter3\register.php on line58

 

 

Could you please help me to fix it?

youThank o

Link to comment
Share on other sites

It works fine when I place the following code directly in the register.php file, instead of writing them in the mysqli_connect.php & then using the statement require(../mysqli_connect.php) in the register.php file!

 

 

DEFINE('DB_USER','root');

DEFINE('DB_PASSWORD','');

DEFINE('DB_HOST','localhost');

DEFINE('DB_NAME','sitename');

$dbc = @mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME) OR die('Could not connect to MySQL: '. mysqli_connect_error());

//set the encoding...

mysqli_set_charset($dbc,'utf8');

 

Sth actually occured, which prevented the statement to execute smoothly:

$r = @mysqli_query($dbc, $q); //Run the query

 

I don't know why???

Link to comment
Share on other sites

I place the mysqli_connect.php in the folder:

C:\xampp\htdocs\mysqli_connect.php

whereas, register.php file in the folder:

C:\xampp\htdocs\Chapter3\register.php

 

I also place a copy of the mysqli_connect.php file in the same folder as the register.php file to check whether mysql is connected (the result is a blank page, so I think I had connected to MySQL before running the following script)

 

 

// Check if errors do not exist

if (empty($errors)) { // If everything's OK

//Include the database connection:

require('../mysqli_connect.php');

//add the user to the database

 

$q = "INSERT INTO users(first_name,last_name,

email, pass, registration_date) VALUES(

'$fn','$ln','$e',SHA1('$p'),NOW())";

$r = @mysqli_query($dbc, $q); //Run the query

//Report on the sucess of the registration:

if ($r) { // If it ran OK

echo '<h1>Thank you!</h1>

<p>You are now registered. In chapter 12 you

will actually be able to log in! </p></p>

<br /></p>';

} else {

echo '<h1>System Error</h1>

<p class="error">You could not be registered due to

a system error. WE apologize for any inconvenience.

</p>';

echo '<p>' . mysqli_error($dbc) . '<br/><br/>Query: ' . $q . '</p>';

} //End of if ($r) IF.

// Close the database connection and compelte the HTML template

mysqli_close($dbc);

include('includes/footer.html');

exit();

}

Link to comment
Share on other sites

 Share

×
×
  • Create New...