473,382 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Session will not register from index.php to search.php

348 100+
Hello all,

I have 2 files. index.php which is a log in page and a search page. After the user logs in they are taken to the search page by way of a checklogin script that verifies the user.

My index page has two fields:

customer
password

Here are the contents of both of my files. I'm sure I am missing something here but 4 hours later and I am stll in the same place.

index.php
[PHP]
<?php session_start(); ?>
</head>
<body>
<form method="post" action="CheckLogin.php">
<div style="text-align: left;">
<table style="margin: 0 auto;">
<tr>
<td><!-- start of dfar body -->
<table class="table">
<tr>
<td><img src="images/logo.gif" alt="" /></td>
</tr>
<tr>
<td><hr /></td>
</tr>
<tr>
<td align="center"><h4>Client Login</h4></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td class="searchReports">
<table cellpadding="5" cellspacing="5">
<tr>
<td>Customer Number:</td>
<td colspan="3"><input class="taskedit_tf" size="20" name="customer" /></td>
</tr>
<tr>
<td>Password:</td>
<td colspan="3"><input class="taskedit_tf" size="20" name="password" /></td>
</tr>
<tr>
<td colspan="3"><input type="image" src="images/query.gif" /></td>
<td><?php echo @$_SESSION['loginerr']; ?></td>
</tr>
</table>
</td>[/PHP]

search.php
[PHP]
<?php session_start(); ?>
<?php echo $customer; ?>
[/PHP]

checklogin.php
[PHP]
<?php
session_start();
ob_start();
include "Persist.php";

$customer=$_POST['customer'];
$password=$_POST['password'];
$sql = "SELECT * from customer where bla bla....";

$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $employee and $password, table row must be 1 row
if($count==1){
// Register $employee, $password and redirect to file "Search.php"
session_register("customer");
session_register("password");
header("location:Search.php?");
}
else {
if(!session_is_registered("customer")){
header("location:index.php");
}
$_SESSION['loginerr'] = "Incorrect Password";
}
ob_end_flush();
?>
[/PHP]

Can someone please shed some light as to what I need to do to pass the customer number from the checklogin script to the search page?

Thanks!!

Frank
Jun 27 '07 #1
3 1922
fjm
348 100+
I got it. hehe. :)


It was on line 14 of checklogin.php. I changed session_register() to [PHP]$_SESSION['customer'] = $customer;[/PHP] and it worked.
I stuck this into the search.php script:

[PHP] <?php
if(!isset($_SESSION['customer'])){
echo 'No Data';
}else{
echo $_SESSION['customer'];
}
?>[/PHP]
and it helped me to see what was happening.

If there is a better way to do this, please advise..

Thanks guys!
Jun 27 '07 #2
pbmods
5,821 Expert 4TB
Heya, Frank.

[PHP] <?php
if(!isset($_SESSION['customer'])){
echo 'No Data';
}else{
echo $_SESSION['customer'];
}
?>[/PHP]
You can also do this:
Expand|Select|Wrap|Line Numbers
  1. echo (isset($_SESSION['customer'])
  2.     ? $_SESSION['customer']
  3.     : 'No Data'
  4. );
  5.  
I like to break it up on multiple lines to make it easier to read, but you can put the whole thing on one line if you want.

http://us2.php.net/manual/sl/languag...comparison.php (look for 'ternary' operator).
Jun 27 '07 #3
fjm
348 100+
Heya, Frank.



You can also do this:
Expand|Select|Wrap|Line Numbers
  1. echo (isset($_SESSION['customer'])
  2. ? $_SESSION['customer']
  3. : 'No Data'
  4. );
  5.  
I like to break it up on multiple lines to make it easier to read, but you can put the whole thing on one line if you want.

http://us2.php.net/manual/sl/languag...comparison.php (look for 'ternary' operator).
Thanks for the link and advice pbmods.. I will research that now! :)
Jun 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Darrell Blake | last post by:
I'm trying to use sessions to allow people to log into my site. The problem is that sometimes it works and sometimes it doesn't! As far as I'm aware my script is fine (hence why it works sometimes)...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
2
by: mr_burns | last post by:
Hi, i am getting the following errors when running my php script: Warning: Cannot send session cookie - headers already sent by (output started at ...
6
by: | last post by:
I ask something relative later but the answer make me cry ;-) If we duplicate the browser window (both in IE / Mozilla), both of 2 browser windows use the same session!!! This produces many...
6
by: John | last post by:
Hi. I am having a few header problems at the moment with a login page. I don't have my headers at the top of the page where I've learned I need to have them. However, I also know I'm supposed...
1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
3
by: Enoch Chan | last post by:
I would like to set a Session variable to a value. In Vbscript it should be Session("ZoomValue")=500 How can I set this session variable by using Javascript? Thanks
4
by: rgparkins | last post by:
Hello I am running out of time with a problem I have running PHP 5.04 and Apache 2.0 and really need help :(. I have a page that stores a variable in session but each time I reload that page the...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.