Jump to content

cant carry variable to another page


optiplex

Recommended Posts

i cant carry the value of $t_nick to another page... 

<?php
ob_start();
$host="localhost"; // Host name 
$username="algebraf_admin"; // Mysql username xx
$password="algebraforex_123"; // Mysql password 
$db_name="algebraf_account"; // Database name 
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $t_nick and $t_password 
$t_nick=$_POST['t_nick']; 
$t_password=$_POST['t_password'];

// To protect MySQL injection (more detail about MySQL injection)
$t_nick = stripslashes($t_nick);
$t_password = stripslashes($t_password);
$t_nick = mysql_real_escape_string($t_nick);
$t_password = mysql_real_escape_string($t_password);

$sql="SELECT * FROM $tbl_name WHERE t_nick='$t_nick' and t_password='$t_password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $t_nick and $t_password, table row must be 1 row

if($count==1){
// Register $t_nick, $t_password and redirect to file "list_details.php"
session_register("t_nick");
session_register("t_password"); 
//echo $t_nick;
//exit;
header("location:list_details.php");
}
else {
echo "Wrong Username or Password";
}

//ob_end_flush();
?>

 

from above, if t_nick and t_password is true, the page will direct to list_details.php... the problem occurs at list_details.php. cannot display any data from database because the t_nick is not carry along.

 

Link to comment
Share on other sites

<?php

session_start();

$host = "localhost"; // Host name 
$username = "algebraf_admin"; // Mysql username xx
$password = "algebraforex_123"; // Mysql password 
$db_name = "algebraf_account"; // Database name 
$tbl_name = "members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $t_nick and $t_password 
$t_nick = $_POST['t_nick']; 
$t_password = $_POST['t_password'];

// To protect MySQL injection (more detail about MySQL injection)
$t_nick = stripslashes($t_nick);
$t_password = stripslashes($t_password);
$t_nick = mysql_real_escape_string($t_nick);
$t_password = mysql_real_escape_string($t_password);

$sql = "SELECT * FROM $tbl_name WHERE t_nick='$t_nick' and t_password='$t_password'";
$result = mysql_query($sql);

// Mysql_num_row is counting table row
$count = mysql_num_rows($result);

// If result matched $t_nick and $t_password, table row must be 1 row
if ($count == 1)
{
// Register $t_nick, $t_password and redirect to file "list_details.php"
$_SESSION["t_nick"] = $t_nick;
$_SESSION["t_password"] = $t_password;

header("location:list_details.php");
}
else
{
echo "Wrong Username or Password";
}

Link to comment
Share on other sites

You need to update your knowledge of how sessions work.

 

This is what php.net has to say about the function session_register()

 

This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

 

So there you go. Do it like so:

 

session_start(); //place this function at the top of your scripts - it's a good habit to get into.

//now say I want to create a session variable called "name" - there's no need for session_register()
$_SESSION['name'] = "Wayne";

 

See? Easy as a Bangkok hooker.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.