Jump to content
Larry Ullman's Book Forums

kingso6

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by kingso6

  1. it shows blank page. one of the password is for my server while the other is for the database i created
  2. Jonathon please i have created a login / logout page and i'm get the same error , like my MySQL is not working fine. shall this is the error message this time: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: NO) in D:\Webpages\login_check.php on line 8 can't connect this is code for the INDEX.PHP: <html><head><title>Login</title></head><body> <form method="post" action="check_login.php"><br />Username: <input type="text" name="username"><br />Password: <input type="password" name="password"><br /><input type="submit" name="submit" value="login"></form></body></html> CHECK_LOGIN.PHP: <?php session_start(); $user="root"; // my server user name $host="localhost"; // server host $password="kingso6"; // this is password for my server $database="site"; // database for server $usertable="users"; // table for database mysql_connect($host, $user, $password) or die ('can not connet'); mysql_select_db($database) or die (mysql_error()); $myusername = $_POST['username']; $mypassword = $_POST['password']; $sql = "SELECT * FROM {$usertable} WHERE username='{$myusername}' AND password='{$mypassword}'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if($count == 1) { $_session["username"] = $myusername; $_session["password"] = $mypassword; header ("location:login_success.php"); // look like culy bracket } else { echo 'Wrong Username OR Password'; } LOGIN_CHECK.PHP: <?php $user="user"; $host="localhost"; $password=""; $database="site"; $usertable="users"; mysql_connect($host, $user, $password) or die ("can't connect"); mysql_select_db($database) or die (mysql_error()); $myusername = $_session['username']; $mypassword = $_session['password']; $sql = "SELECT * FROM {$usertable} WHERE username='{$myusername}' AND password='{$mypassword}'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if ($count == 0) { header("location:index.php"); } LOGIN_SUCCESS.PHP: <?php require_once("login_check.php"); ?> <html> <head> <title> Login Success</title> </head> <body> Welcome back <?php echo $myusername; ?> <br /> <a $set="logout.php">Logout</a> </body> </html> THE DATABASE NAME IS 'site' while the database table is 'users' username for the table created is 'admin' password 'kingso' PLEASE HELP AND FOUND OUT WHAT IS WRONG WITH MY SERVER
  3. Thanks Jonathon for helping me. i have fixed that but yet still getting the same error report when i submit the registration form: could not connect to MySQL: Access denied for user 'username'@'localhost' (using password: YES). please help me out am stuck
  4. larry i used the script in your book title PHP 6 and MySQL 5 for Dynamic web sites chapter 8, the registration script did not work for me rather i'm getting ' could not connect to MySQL: Access denied for user 'username'@'localhost' (using password: YES) ' and i try debugging it by making sure that MySQL server is running by starting my MySQL and it started i even created another database with it name user but to no avial but i was able to login to PHPMYADMIN . i'm using MYSQL version 5.5.17 apache 2.2.21 PHP 5.2.17 phpmyadmin 3.4.7.1 OS window 7 this is the code for mysqli_connect <?php // this file contains the database access information. DEFINE ('DB_USER', 'username'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // make the connection $bdc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('could not connect to MySQL: ' . mysqli_connect_error() ); ?> this is the code for the registration <?php # register.php $page_title = 'Register'; include ('includes/header.html'); // check if the form has been submitted: if (isset($_POST['submitted'])) { $errors = array(); // initialize an error array. // check for a first name: if (empty($_POST['first_name'])) {$errors[] = 'you forget to enter your first name.'; } else { $fn = trim($_POST['first_name']); } // check for a last name: if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } // check for the email address : if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = trim($_POST['email']); } // check for a password and match agaist the confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // if everything is ok // register the user in the database require_once ('includes/mysqli_connect.php'); //connect to the database. // make the query: $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 if ($r) { //if it ran ok // print a message: echo '<h1>Thank you!</h1> <p>You are now registered. go to your mail to confirm the registration then you can be able to log in!</p><p><br /></p>'; } else { // if it did not run ok // public message: echo '<h1>System Error</h1> <p class="error"> You could not be registered due to a system error. We apologize for any inconvinience.</p>'; // debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // end of if ($r) IF mysqli_close($dbc); // close the database connection. // include the footer and quit the script: include ('includes/footer.html'); exit(); } else { // report the error echo '<h1>error!</h1> <p class="error">The following error(s) occured:<br />'; foreach ($errors as $msg) { //print each error echo " $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // end of if (empty ($errors)) IF . } // End of the main submit conditonal. ?> <h1>Register</h1> <form action="register.php" method="post"> <p>First name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Password: <input type="password" name="pass1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('includes/footer.html'); ?> please any help will be appreciated
×
×
  • Create New...