intertho Posted February 17, 2012 Share Posted February 17, 2012 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 More sharing options...
HartleySan Posted February 17, 2012 Share Posted February 17, 2012 Sounds like your DB connection is no good. Link to comment Share on other sites More sharing options...
intertho Posted February 17, 2012 Author Share Posted February 17, 2012 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 More sharing options...
HartleySan Posted February 17, 2012 Share Posted February 17, 2012 That means that the path or name of the file in the require function is wrong. What's the relation between the PHP script and the MySQLi file? Link to comment Share on other sites More sharing options...
intertho Posted February 17, 2012 Author Share Posted February 17, 2012 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 More sharing options...
HartleySan Posted February 17, 2012 Share Posted February 17, 2012 Does your DB connection script work with other PHP scripts? I have a feeling either the DB script is wrong (i.e., you're providing the wrong user name, password, host name, etc.) or your database is not set up properly. Is you DB properly set up through MySQL? Link to comment Share on other sites More sharing options...
intertho Posted February 22, 2012 Author Share Posted February 22, 2012 I've fixed it! Thanks bro Link to comment Share on other sites More sharing options...
Larry Posted February 22, 2012 Share Posted February 22, 2012 Could you post the solution so that others might benefit from your experience? Link to comment Share on other sites More sharing options...
Recommended Posts