Jump to content

Imtiyaaz

New Members
  • Posts

    7
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Imtiyaaz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Correct. The login form is displayed before session_start(); Could this be the problem? Should my PHP code be before the form or after?
  2. Hi It does not give a blank page. Its gives the same page but just clears the form after I click the submit button. I have echoed out the $username and $EncPass after the below line and it gave the correct username and password. Could it be a browser issue? I was testing on firefox if (isset($_POST['login'])) { //if submit button is clicked, the below query will run $result = mysqli_query($connection,"SELECT * FROM member WHERE username='$username' AND password='$EncPass'"); //query to check if username and password matches what is stored in the user table to me it seem the problem lies somewhere here: if($result) { if(mysqli_num_rows($result)) { session_start(); // start a session $_SESSION['username'] = "$username"; //store username in the session header("location:members_area.php"); // redirects to the members area } else echo "<p align = 'center'>Incorect login! Please try again, or proceed to <a href='register.php'> Register </a></p>"; } but I cannot understand why it works on the testing server on not on the live site. It does not even print the line Incorect login! Please try again, or proceed to <a href='register.php'> Register </a>
  3. Hi Im having trouble logging into the live site. The below works perfectly in my testing environment but as soon as I test it on the live domain when I enter in the login details and submit it just clears the login form and does not login. I have checked the database after registering an account and it store the username and encrypted pass just as it stores it in my testing database. Any help will be appreciated. My register.php is as follows: <?php include('connect.php'); //Define variable submitted by the form $Register = $_POST['register']; $title = $_POST['title']; $name = $_POST['name']; $surname = $_POST['surname']; $email = $_POST['email']; $username = $_POST['username']; $password1 = $_POST['password']; $password2 = $_POST['conf_password']; $EncPass = sha1($password1); if (isset($_POST['register'])) { //check if submit button was selected if($name == "" or $surname == "" or $username == "" or $password1 == "" or $password2 == ""){ //check if fields in the form is empty echo "<p align = 'center'>Please enter all required fields</p>"; } else{ $result = mysqli_query($connection,"SELECT username FROM member WHERE username='$username'"); //selects the username from the user table in the database that is the same as the username submitted by the form $num_rows = mysqli_num_rows($result); //checks the number of rows with this username if($num_rows > 0){ //if number of rows is more than 0, the below will be displayed echo "<p align='center'>The user $username already exists! Proceed to <a href=login.php>Login</a></p>"; } else{ if($password1 == $password2){ //check if the passwords match //Create query $query = "INSERT INTO member (title, name, surname, email, username, password) VALUES ('$title', '$name', '$surname', '$email', '$username', '$EncPass')"; //inserts the data that was entered in the form into the user table $result = mysqli_query($connection,$query); if($result){ //if the query is successful, the below will be displayed echo "<p align='center'>Registration Succesful. Proceed to <a href=index.php>Login</a>!</p>"; } } else{ echo "<p align='center'>The Passwords does not match! Please try again</p>"; //Print a message to the user that passwords do no match } } } } ?> index.php: <?php include('connect.php'); //Define variable submitted by the form $Login = $_POST['login']; $username = $_POST['username']; $password1 = $_POST['password']; $EncPass = sha1($password1); if (isset($_POST['login'])) { //if submit button is clicked, the below query will run $result = mysqli_query($connection,"SELECT * FROM member WHERE username='$username' AND password='$EncPass'"); //query to check if username and password matches what is stored in the user table if($result) { if(mysqli_num_rows($result)) { session_start(); // start a session $_SESSION['username'] = "$username"; //store username in the session header("location:members_area.php"); // redirects to the members area } else echo "<p align = 'center'>Incorect login! Please try again, or proceed to <a href='register.php'> Register </a></p>"; } } ?>
  4. Hi Can anyone tell me why this code is not displaying anything besides book: Im new to OOP in php and need some help getting the following to run properly <?php class ShopProduct{ public $title = "Where eagles dare"; public $producerMainName = "McLean"; public $producerFirstName = "Alistair"; public $price = 179; function getProducer(){ return "{$this->producerFirstName}"; "{$this->producerMainName}"; } } $product1 = new ShopProduct(); $product1->title=""; $product1->producerMainName=""; $product1->producerFirstName=""; $product1->price=""; print "Book: {$product1->getProducer()}\n"; ?>
  5. Hi Im having a bit of trouble with my leap_year() function. If I enter in any year it prints "Leap Year" even if I enter in a year that is not a leap year. Below is my form and php...Please assist <form Method = "POST" ACTION = "leap.php"> <input type = "text" name = "year" /> <br><br> <input type ="submit" name= "check_year" value="Check" /> </form> <?php error_reporting(0); // turn error messages off //Declare variables $Check = $_POST['check_year']; $year = $_POST['year']; if (isset($_POST['check_year'])) { leap_year(); } function leap_year() { if((($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0))){ echo "Leap Year"; } else{ echo "Not a leap year"; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.