Jump to content


Photo

Urgent help needed for Passing values from one page to another


  • Please log in to reply
4 replies to this topic

#1 ramu_rp2005

ramu_rp2005
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 13 March 2006 - 11:04 AM

i've sent a value from one page to another,as

<a href="browsedirectory.php?typeid=<? echo $id ?>" target=main><font size=2 face="Tahoma"><? echo $name ?></font></a>

Now,how to obtain and use the value of typeid in browsedirectory.php .


if i use echo typeid; in browsedirectory.php it shows nothing is their.so how do i obtain this value.

#2 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 13 March 2006 - 11:11 AM

First off try

<a href="browsedirectory.php?typeid=<? echo"$id"; ?>" target=main><font size=2 face="Tahoma"><? echo"$name"; ?></font></a>

then in browsedirectory.php:

echo $_GET['typeid'];

that should do it


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 March 2006 - 03:03 PM

You wrote:
<?php
<a href="browsedirectory.php?typeid=<? echo $id ?>" target=main><font size=2 face="Tahoma"><? echo $name ?></font></a>
?>
Where is the variable $id getting set? If you put the line
<?php echo $id . "<br />"; ?>
just befor the above statement, what gets displayed on your browser?

BTW
<?php echo $id ?>
is exactly the same as
<?php echo "$id"; ?>

Ken

#4 psyion

psyion
  • Members
  • PipPip
  • Member
  • 13 posts
  • LocationKota Kinabalu, Sabah, Malaysia.

Posted 13 March 2006 - 08:33 PM

okey i'm also learning here... i just learn php for like about 2 weeks now... still learning thou.
i hope the codes help ramki.

The code that i give are partially made from dreamweaver using "record insertion form wizard" and modified just to send variable but not an sql. I found this way of passing variable while i was stuck with a page where i need to pass names and other variables only.

But i need some explenation on some part that i really don't know what does the code mean.

"code discription passing a variable name id from pageOne.php to pageTwo.php."

pageOne.php
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["hiddenField"])) && ($_POST["hiddenField"] == "form1")) {
$id = $_POST['id'];

  $insertGoTo = "pageTwo.php?id=$id";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>pageOne</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php echo $editFormAction; ?>">
  <input name="hiddenField" type="hidden" value="form1" />
  Input id
    <input name="id" type="text" id="id" />
  <input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>

pageTwo.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>pageTwo</title>
</head>

<body>
id given is = 
<?php echo $_GET['id']; ?>
</body>
</html>

so what does this part of the code mean and what is happening here?

<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["hiddenField"])) && ($_POST["hiddenField"] == "form1")) {
$id = $_POST['id'];

  $insertGoTo = "pageTwo.php?id=$id";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

?>

And can you guys here teach me the easyway of doing this so i don't need to copy here and cut there just to pass a variable. i got the feeling that the code written have gone a really long way just to pass a variable. thank you.

#5 psyion

psyion
  • Members
  • PipPip
  • Member
  • 13 posts
  • LocationKota Kinabalu, Sabah, Malaysia.

Posted 13 March 2006 - 08:34 PM

sorry it was a double post.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users