Page 1 of 1

Accessing and carrying form value

Posted: Fri Jul 01, 2005 11:32 pm
by tycoon
Hi All…I’m trying to access form values, so that I can used them on other pages. Can anybody show me how I can access and carry the value of $username to my next(add.php) page..Below I attach my code

Code: Select all

index.php (first page)

<form name=&quote;form1&quote; method=&quote;post&quote; action=&quote;logcheck.php&quote;>
    <table width=&quote;200&quote; border=&quote;0&quote;>
      <tr>
        <td colspan=&quote;2&quote;>Login</td>
      </tr>
      <tr>
        <td width=&quote;87&quote;>Username</td>
        <td width=&quote;103&quote;><input name=&quote;username&quote; type=&quote;text&quote; id=&quote;username&quote;></td>
      </tr>
      <tr>
        <td>Password</td>
        <td><input name=&quote;password&quote; type=&quote;text&quote; id=&quote;password&quote;></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input type=&quote;submit&quote; name=&quote;Submit&quote; value=&quote;Submit&quote;></td>
      </tr>
    </table>
  </form>

Code: Select all

logcheck.php (second page)

<?php

session_start();
header(&quote;Cache-control: private&quote;);

$_SESSION&#1111;'username'] = $_POST&#1111;'username']; 
$_SESSION&#1111;'password'] = $_POST&#1111;'password']; 


$db = @mysql_connect('localhost', 'root') or die('could not connect to mysql db, the server return the error:'.mysql_error());
mysql_select_db(&quote;timelinesys&quote;,$db) or die('could not connect to mysql db, the server return the error:'.mysql_error());
$query = &quote;select * from user where username='$username' and password='$password'&quote;;
$sql = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($sql);
$row = mysql_fetch_array($sql);

if ($count >= 1)
{
header('Location: add.php'); 
}
else
{
 header('Location: loginfailed.php'); 
}
?>

Code: Select all

add.php (third page)

<?php
session_start();
header(&quote;Cache-control: private&quote;);
$_REQUEST&#1111;'username'] = $_SESSION&#1111;'username']; 
?>
<html>
<head>
<meta http-equiv=&quote;Content-Type&quote; content=&quote;text/html; charset=iso-8859-1&quote;>
<title>Untitled Document</title>
</head>

<body>
Welcome <? php echo $_SESSION&#1111;'username']; ?>
<br>
</body>
</html>

Posted: Fri Jul 01, 2005 11:40 pm
by Burrito
it looks to already be done as you've set the value of your post var to a session var.

you can use that session var on any page that is running sessions now.

Posted: Sat Jul 02, 2005 12:02 am
by tycoon
but still it won't output <? php echo $_SESSION['username']; ?> instead it only output Welcome

Posted: Sat Jul 02, 2005 12:16 am
by Burrito
try print_r'ing your session array on the login check page after you've set those two vars to see if they're actually being set. If not, I'm guessing you have a server config issue for sessions.

Posted: Sat Jul 02, 2005 12:24 am
by tycoon
i'm totally a newbie...i can't realy follow your instruction..can u explain a bit detailed more..sorry for any inconvenience

Posted: Sat Jul 02, 2005 9:27 am
by Sphen001
Hi,

Try putting this code on the page you want the variable to appear.

Code: Select all

echo '<pre>';
print_r($_SERVER);
echo '</pre>';
Hope this helps :D

Sphen001

Posted: Sat Jul 02, 2005 9:42 am
by timvw
I think you'll get more valuable information if you add the following at the beginning of each of your scripts:

Code: Select all

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

Posted: Sat Jul 02, 2005 9:43 am
by tycoon
the page out put

Array
(
[COMSPEC] => C:\\WINDOWS\\system32\\cmd.exe
[DOCUMENT_ROOT] => c:/apache/htdocs
[HTTP_ACCEPT] => image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT_LANGUAGE] => en-us
[HTTP_CACHE_CONTROL] => no-cache
[HTTP_CONNECTION] => Keep-Alive
[HTTP_COOKIE] => CFID=600; CFTOKEN=85129997; PHPSESSID=e5b2c5fd65388ff1df00b3cd824fc6e1
[HTTP_HOST] => localhost
[HTTP_REFERER] => http://localhost/Timesys/telephone/index.php
[HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
[PATH] => C:\\CFusionMX7\\verity\\k2\\_nti40\\bin;C:\\JRun4\\verity\\k2\\_nti40\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\Program Files\\MySQL\\MySQL Server 4.1\\bin
[REDIRECT_STATUS] => 200
[REDIRECT_URL] => /Timesys/telephone/add.php
[REMOTE_ADDR] => 127.0.0.1
[REMOTE_PORT] => 2464
[SCRIPT_FILENAME] => c:/apache/php/php.exe
[SERVER_ADDR] => 127.0.0.1
[SERVER_ADMIN] => admin@localhost
[SERVER_NAME] => localhost
[SERVER_PORT] => 80
[SERVER_SIGNATURE] => Apache/1.3.23 Server at localhost Port 80

[SERVER_SOFTWARE] => Apache/1.3.23 (Win32)
[SystemRoot] => C:\\WINDOWS
[WINDIR] => C:\\WINDOWS
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /Timesys/telephone/add.php
[SCRIPT_NAME] => /php/php.exe
[PATH_INFO] => /Timesys/telephone/add.php
[PATH_TRANSLATED] => c:\\apache\\htdocs\\timesys\\telephone\\add.php
[PHP_SELF] => /Timesys/telephone/add.php
[argv] => Array
(
)

[argc] => 0
)

Posted: Sat Jul 02, 2005 9:57 am
by timvw
My first guess is that you need to edit your php.ini ;)

Change the line:

Code: Select all

session.save_path = &quote;/tmp&quote;
to something like (make sure c:/windows/temp/session exists):

Code: Select all

session.save_path = &quote;C:/windows/temp/sessions&quote;
Btw, you might want to read what the issues are in a shared hosting environment if you use the default session.save_path