Jump to content

Urgent help needed for Passing values from one page to another


ramu_rp2005

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.
Link to comment
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
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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