Jump to content

Archived

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

ramu_rp2005

Urgent help needed for Passing values from one page to another

Recommended Posts

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.

Share this post


Link to post
Share on other sites
First off try

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

then in browsedirectory.php:

[code]
echo $_GET['typeid'];
[/code]

that should do it

Share this post


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

BTW
[code]<?php echo $id ?>[/code] is exactly the same as [code]<?php echo "$id"; ?>[/code]

Ken

Share this post


Link to post
Share on other sites
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
[code]<?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>[/code]

pageTwo.php
[code]<!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>[/code]

[b]so what does this part of the code mean and what is happening here?[/b]

[code]<?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));
}

?>[/code]

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.

Share this post


Link to post
Share on other sites

×

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.