optiplex Posted July 22, 2009 Share Posted July 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 You aren't calling session_start() Quote Link to comment Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 <?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"; } Quote Link to comment Share on other sites More sharing options...
optiplex Posted July 22, 2009 Author Share Posted July 22, 2009 You aren't calling session_start() i've call session.. here the coding session_start(); if(!session_is_registered(t_nick)){ header("location:login.php"); } and still doesn't work... :'( Quote Link to comment Share on other sites More sharing options...
waynew Posted July 22, 2009 Share Posted July 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
9three Posted July 22, 2009 Share Posted July 22, 2009 session_register() is deprecated. Use $_SESSION['variable'] instead. See? Easy as a Bangkok hooker. Nice! Quote Link to comment Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 If you are not familiar I suggest reading through the Session Handling section at php.net http://us.php.net/manual/en/book.session.php The examples section will be truly helpful in understanding how to pass variables with sessions. Quote Link to comment Share on other sites More sharing options...
optiplex Posted July 22, 2009 Author Share Posted July 22, 2009 session_register() is deprecated. Use $_SESSION['variable'] instead. See? Easy as a Bangkok hooker. Nice! ermmm.. ive put this.. $_SESSION['t_nick']='$t_nick'; but.. still facing the same problem.. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 $_SESSION['t_nick']='$t_nick'; That's just going to set the session variable $_SESSION['t_nick'] equal to the LITERAL string '$t_nick'. Are you using session_start() ? Quote Link to comment Share on other sites More sharing options...
optiplex Posted July 22, 2009 Author Share Posted July 22, 2009 i've remove session_start(); still blur :'( Quote Link to comment Share on other sites More sharing options...
9three Posted July 22, 2009 Share Posted July 22, 2009 On top of your page it MUST have session_start() otherwise $_SESSION will not work properly. So do session_start() THEN set your variables into your session. session_start(); $_SESSION['name'] = 'FirstName!'; Quote Link to comment Share on other sites More sharing options...
optiplex Posted July 22, 2009 Author Share Posted July 22, 2009 ermm.. doesnt work at all ... Quote Link to comment Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 It works, 9 billion websites use this daily, you just aren't doing it right Use google, follow a tutorial. http://www.tizag.com/phpT/phpsessions.php Quote Link to comment Share on other sites More sharing options...
optiplex Posted July 22, 2009 Author Share Posted July 22, 2009 It works, 9 billion websites use this daily, you just aren't doing it right Use google, follow a tutorial. http://www.tizag.com/phpT/phpsessions.php hahahaha.. i doing the tutorial right now.. tq for the helping.. u r very nice Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.