Announcements | Last Post | |
---|---|---|
SoC Curricula | 09/30/2017 01:08PM | |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |
Unisa contact information | 07/28/2011 01:28PM |
problem with my website October 11, 2013 09:29AM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 11, 2013 10:59AM |
Registered: 10 years ago Posts: 23 Rating: 0 |
Re: problem with my website October 11, 2013 12:04PM |
Registered: 11 years ago Posts: 106 Rating: 0 |
Re: problem with my website October 11, 2013 12:16PM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 14, 2013 11:08AM |
Registered: 11 years ago Posts: 51 Rating: 0 |
This code works perfectly on the local server.Language: PHPif ($num_rows <= 0){ echo "Sorry, there is no username $username with the specified password."; echo "Try again"; echo "<a href = ';index.php';>Back</a>"; exit; } else { $_SESSION[';user';]= $_POST["username"]; header("location:logged.php");// This is the page where we will be redirect after loging in } }
Re: problem with my website October 14, 2013 11:44AM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Quote
even when the password is incorrect,it still redirect me to the index page instead of the logged in page
Re: problem with my website October 14, 2013 03:21PM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 14, 2013 04:19PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: problem with my website October 15, 2013 04:38PM |
Registered: 11 years ago Posts: 51 Rating: 0 |
i don't know where to check for the php.ini of the host server,should i do it manually or?Language: PHP<?php //This is the login page.A username is matched with the corresponding password before loging in // $username = "root";// Mysql username $password = "";// Mysql password $database = "userlogin"; // Database name $server = "127.0.0.1"; // Server name // Connect to server and select database. $db = mysql_connect($server,$username,$password) or DIE("oops,something went wrong"); mysql_select_db($database,$db) or DIE("oops,something went wrong"); //Starting a session session_start(); if($_SERVER ["REQUEST_METHOD"] == "POST") { $username = $_POST["username"]; //username is stored in $username variable. $password = $_POST["password"]; //password is stored in $password variable. $match = "select id from login where username = ';".$_POST[';username';]."';and password = ';".$_POST[';password';]."';;"; $qry = mysql_query($match); $num_rows = mysql_num_rows($qry); //Check if $num_rows variable is true if ($num_rows <= 0){ echo "Sorry, there is no username $username with the specified password."; echo "Try again"; echo "<a href = ';index.php';>Back</a>"; exit; } else { $_SESSION[';user';]= $_POST["username"]; header("location:logged.php");// This is the page where we will be redirect after loging in } } echo"<body bgcolor=';#E0FFFF';>"; echo"<p>Please enter your username and your password or <a href=';index.php';>click here</a> to go back to the index page</p>"; echo"<form action = '; '; method = ';post';>"; echo"<label>Username:</label>"; echo"<input type = ';text'; name = ';username';/><br/>"; echo"<label>Password:</label>"; echo"<input type = ';password'; name = ';password';/><br/>"; echo"<input type = ';submit'; value = ';Login';/><br/>"; echo"</form>"; echo"</body>"; ?>
Re: problem with my website October 15, 2013 05:20PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Language: PHPif($_SERVER ["REQUEST_METHOD"] == "POST") // Rather change this as below. { $username = $_POST["username"]; //username is stored in $username variable. // Why do you store these values in variables, and then not use the variables ??? $password = $_POST["password"]; //password is stored in $password variable.
Language: PHPif (isset($_POST[';submit';]) // Add name="submit" to the form input submit. {
to check if it gives the expected results.Language: PHP$num_rows = mysql_num_rows($qry);
Re: problem with my website October 15, 2013 05:36PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: problem with my website October 15, 2013 07:28PM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 15, 2013 08:20PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Language: PHPor die("SQL query error: ".mysql_error());
Language: PHP$num_rows = mysql_num_rows($qry);
Language: PHP$num_rows = 1;
Re: problem with my website October 16, 2013 10:04AM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 16, 2013 10:46AM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Language: PHPif (mysql_error()) { echo "SQL error: ". mysql_error(); // Putting in <br> would improve layout echo "Line number: ".mysql_errno(); } else { echo "Something to identify the SQL statement"; echo "No SQL error occurred"; }
Re: problem with my website October 16, 2013 11:36AM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 16, 2013 11:58AM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: problem with my website October 16, 2013 12:26PM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 16, 2013 01:27PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Language: PHP// Connect to server and select database. $db = mysql_connect($server,$username,$password) or DIE("oops,something went wrong"); /* // Comment out the rest of the PHP script. mysql_select_db($database,$db) or DIE("oops,something went wrong"); // When you have checked that the above works, move the opening comment tag here. //Starting a session session_start(); // Comment this out. if($_SERVER ["REQUEST_METHOD"] == "POST") { $username = $_POST["username"]; //username is stored in $username variable. $password = $_POST["password"]; //password is stored in $password variable. $match = "select id from login where username = ';".$_POST[';username';]."';and password = ';".$_POST[';password';]."';;"; // When above works, move opening comment tag here. Add a closing bracket before the comment tag. Move comment tag and test each of following SQL when above ones work. $qry = mysql_query($match); $num_rows = mysql_num_rows($qry); //Check if $num_rows variable is true if ($num_rows <= 0){ echo "Sorry, there is no username $username with the specified password."; echo "Try again"; echo "<a href = ';index.php';>Back</a>"; exit; } else { $_SESSION[';user';]= $_POST["username"]; header("location:logged.php");// This is the page where we will be redirect after loging in } } */ // Closing comment tag
Re: problem with my website October 16, 2013 02:59PM |
Registered: 11 years ago Posts: 51 Rating: 0 |
Re: problem with my website October 21, 2013 06:53AM |
Registered: 10 years ago Posts: 7 Rating: 0 |