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. Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/ Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 You aren't calling session_start() Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880676 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"; } Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880681 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... :'( Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880683 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. Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880687 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! Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880690 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. Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880697 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.. Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880701 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() ? Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880704 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 :'( Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880707 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!'; Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880711 Share on other sites More sharing options...
optiplex Posted July 22, 2009 Author Share Posted July 22, 2009 ermm.. doesnt work at all ... Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880718 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 Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880726 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 Link to comment https://forums.phpfreaks.com/topic/167033-cant-carry-variable-to-another-page/#findComment-880728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.