bluestar Posted May 14, 2011 Share Posted May 14, 2011 i am making a website and some part of which is to show user information...for this i had make a class and functions within it...one of the function is for retrieving values from database(im using mysql)...i know a variable is limited only in function,also tried $_session for this too..the function works fine ....but it is not sendind the information to the page from where im calling it...here is my code..... in xyz.php file <?php class book{ public $v1; public $v2; public $v3; function book(){ } function page1(){ $this->con=mysql_connect("localhost","root","usa"); $this->db=mysql_select_db("truth",$this->con); } function page2($xyz){ $this->page1(); $query="SELECT * FROM member_signup WHERE Uid=$xyz"; $result=mysql_query($query,$this->con); $result1=mysql_fetch_array($result); $_SESSION['info']=$result1; return $_SESSION['info']; return $result1; } }?> in show.php file <? require_once("xyz.php"); $pen = new book; if($pen->page2(100011)) { session_start(); if (mysql_error()) { print "Database ERROR: " . mysql_error(); } else{ echo "cows"; echo "<br>cows<br>"; echo "my name is'".$_SESSION['info']."'"; echo "my name is'".$_SESSION['FIRST_NAME']."'"; //i have a fied is db named FIRST_NAME } } else{echo "happy";} ?> Link to comment https://forums.phpfreaks.com/topic/236401-in-php-retrieving-value-from-dbmysql-and-passing-it-to-other-pages/ Share on other sites More sharing options...
anupamsaha Posted May 14, 2011 Share Posted May 14, 2011 In your show.php file, put session_start() before require_once(). It will work. Thanks! Link to comment https://forums.phpfreaks.com/topic/236401-in-php-retrieving-value-from-dbmysql-and-passing-it-to-other-pages/#findComment-1215477 Share on other sites More sharing options...
tsm1248 Posted May 15, 2011 Share Posted May 15, 2011 As a die not Object oriented PHP is very bad for app performance and memory. Its only positive aspect is team readability and maintenance. I would suggest making your code more static. If your calling the data from a previous page consider a form to post data to the next page or storing info in cookies or sessions. Also make sure you don't have any headers in the way so that the cookie/session can be created, and make sure they are secure. Link to comment https://forums.phpfreaks.com/topic/236401-in-php-retrieving-value-from-dbmysql-and-passing-it-to-other-pages/#findComment-1215616 Share on other sites More sharing options...
doddsey_65 Posted May 15, 2011 Share Posted May 15, 2011 Add more public vars like $username then in page2 function set them like so $this->username = $row['username']; then in the file you wish to display them use $book = new book(); echo $book->username; Link to comment https://forums.phpfreaks.com/topic/236401-in-php-retrieving-value-from-dbmysql-and-passing-it-to-other-pages/#findComment-1215620 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.