Jump to content

in php, retrieving value from db(mysql) and passing it to other pages


bluestar

Recommended Posts

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";}

 

?>

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.

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;

Archived

This topic is now archived and is closed to further replies.

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