mysql - Error with PHP Form, Keeps Redirecting to login page -


ok here issue. have created simple login system few pages. works. created page php form submits input mysql database. works well...on other pages on site.
reason, when submit form, keeps redirecting login page , have no idea why. here form/code trying submit:

<form method="post" action="admin_home.php?page=search.php"> <p>search date range: </p> from: <input type="text" id="from" name="from" />to: <input type="text" id="to" name="to" /> <br> <p>search by:</p> name: <input type="text" id="name" name="name" /> phone number: <input type="text" id="phone" name="phone" /> <input name="export" type="submit" value="search" /> </form> 

that form in file search.php search results displayed below form. here login code have on admin_home.php page:

<?php session_start(); require("admin_logincheck.php"); if (!(isset($_session['name']) && $_session['name'] != '')) {  header ("location: admin_index.php");  } ?> 

....then displaying whatever.

and here admin_logincheck.php page:

<?php session_start(); session_name("memberlogin");   $hostname = ""; $username = ""; $dbname = ""; $password = "";  if($_get['action'] == "login") {  mysql_connect($hostname, $username, $password) or die ("unable connect database! please try again later."); mysql_select_db($dbname);   $name = $_post['user']; $q_user = mysql_query("select * users username='$name'");  if(mysql_num_rows($q_user) == 1) {  $query = mysql_query("select * users username='$name'"); $data = mysql_fetch_array($query); if($_post['pass'] == $data['password']) { $_session['name'] = $name; header("location: admin_home.php"); // page want open if user logs in website. exit; }             else {                 header("location: admin_index.php?login=failed&cause=".urlencode('wrong password'));                 exit;             }  }  else {     header("location: admin_index.php?login=failed&cause=".urlencode('invalid user')); exit; } }  // if session not registered //if(session_is_registered("name") == false) { if ($_session['name'] == false) {    header("location: admin_index.php"); } ?> 

my other pages fine, reason 1 form/search page keeps redirecting login page. appreciated. hope made sense lol.

replace :

if (!(isset($_session['name']) && $_session['name'] != '')) { header ("location: admin_index.php"); } 

with this:

if (isset($_session['name']) && !empty($_session['name'])) { header ("location: admin_index.php"); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -