anilvaghela Posted July 27, 2009 Share Posted July 27, 2009 Hi.... I have created a php mysql login scripts for a web project and i have moved this from dev to live server but realised that mysqli extension will not be allowed and i will have to work with mysql extentsions only. Below I have 2 files. 1 - Mysqli Connection File ( need to know what is needed to be changed in here to mysql) <?php # Script 16.4 - mysqli_connect.php // This file contains the database access information. // This file also establishes a connection to MySQL // and selects the database. // Set the database access information as constants: DEFINE ('DB_USER', 'user'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'host'); DEFINE ('DB_NAME', 'db'); // Make the connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (!$dbc) { trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error() ); } ?> 2 - Registration Page, on this page i just need to work out how to change some of the functions which rely on mysqli to be converted to mysql... <?php # Script 16.6 - register.php // This is the registration page for the site. include ('includes/header.html'); require_once ('includes/config.inc.php'); $page_title = 'Register'; if (isset($_POST['submitted'])) { // Handle the form. require_once (MYSQL); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { // Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at <URL TO BE REDIRECTED TO>. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: '); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> Your support will be appreciated. Thanks Anil Vaghela anil@heavyvibesonline.com www.heavyvibesonline.com Quote Link to comment https://forums.phpfreaks.com/topic/167603-mysqli-functions-convert-them-to-mysql/ Share on other sites More sharing options...
corbin Posted July 27, 2009 Share Posted July 27, 2009 In most of those cases you should just be able to change mysqli_ to mysql_. Have you tried anything? Quote Link to comment https://forums.phpfreaks.com/topic/167603-mysqli-functions-convert-them-to-mysql/#findComment-884104 Share on other sites More sharing options...
anilvaghela Posted July 30, 2009 Author Share Posted July 30, 2009 yes i have attempted this but i still have problems Quote Link to comment https://forums.phpfreaks.com/topic/167603-mysqli-functions-convert-them-to-mysql/#findComment-886757 Share on other sites More sharing options...
Philip Posted July 30, 2009 Share Posted July 30, 2009 So what errors are you getting? Like Corbin said, most of those you can just remove the i from mysqli_ Quote Link to comment https://forums.phpfreaks.com/topic/167603-mysqli-functions-convert-them-to-mysql/#findComment-887065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.