/    Sign up×
Community /Pin to ProfileBookmark

Passing Variable

How do i pass on a variable through php files

I.e i have linked to another php document and i need to use the variable $AuctionID from the original document

how do i do that, the new page has this on

[code=php]
<?PHP

//conn
$conn = mysql_connect(“localhost”, “k0m0d0”, “ragnarok”) or die(mysql_error());

//select db
mysql_select_db(“ebay”,$conn) or die(mysql_error());

//statement
$sql = “SELECT Source FROM auctions WHERE ID = ‘$AuctionID'”;

//if script
$result = mysql_query($sql, $conn) or die(mysql_error());
if (mysql_num_rows($result) ==1) {

//fetch results
$row = mysql_fetch_array($result);

//extract is into the echo
extract($row);

echo “$Source”;
};
?>
[/code]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@k0r54authorAug 12.2004 — Do i need to use something like this

$AuctionID = $HTTP_POST_VARS['AuctionID']
Copy linkTweet thisAlerts:
@theuedimasterAug 12.2004 — You can use sessions here. The following code is an example. This is to be put before the <html> tag. On the link or what not to go to the other page put the thing in the second quote.


<?php

if(isset($func) && $func == 1)

{

session_start();

$_SESSION['casecolorphp'] = $_POST['casecolor'];

$_SESSION['packagephp'] = "2.8 Economy";

/* Above is package name */

$_
SESSION['pricephp'] = $_POST['price'];

$_
SESSION['osphp'] = $_POST['os'];

header("Location: http://sigmaseven.net/areyousure.php");

}

else {

?>
[/quote]

Here is an example of using a form to transfer data, it is to be used with the quote above:


<form name="buyform" id="buyform" action="<?PHP echo($_SERVER['PHP_SELF']); ?>?func=1" method="post">

<input type="hidden" name="casecolor" value="0">

<input type="hidden" name="package" value="p4 2.8 Economy">

<input type="hidden" name="price" value="0">

<input type="hidden" name="os" value="0">

<input type="image" src="../Images/Otherpics/buynow.jpg" name="submit" alt="Make payments to Sigma Seven with PayPal - it's fast, free and secure!">

</form>
[/quote]


The action part:

action="<?PHP echo($_SERVER['PHP_SELF']); ?>?func=1"

is important. If it is a link, this should be where it goes.

To then get the information on any other page do this:


<?php

session_start();

$pricebuynow = $_SESSION['pricephp'];

$packagebuynow = $_
SESSION['packagephp'];

$osbuynow = $_SESSION['osphp'];

$casecolorbuynow = $_
SESSION['casecolorphp'];

$message = $packagebuynow . "| $" . $pricebuynow . "| $" . $osbuynow . "| " . $casecolorbuynow;

mail("[email protected]", "New Sale Paypal", $message);

?>
[/quote]


See how you can UNsession it? ?
Copy linkTweet thisAlerts:
@theuedimasterAug 12.2004 — You should do this if you want to use the information on multiple pages...it makes it much easier. However, if you are only using for two pages which are right after each other, then use post.
Copy linkTweet thisAlerts:
@k0r54authorAug 13.2004 — Hey i have put this on the page that the link goes to. Im a bit lost if possible could some1 put in remarks and start the session for me.I have done sessions before but i think im confussing myself

Below is the page that the link goes to

[code=php]
<?PHP
//session
if(isset($func) && $func == 1)
{

//start session
session_start();
$_SESSION['AuctionID'] = $_POST['AuctionID'];
header("Location: http://sigmaseven.net/areyousure.php"); //when does it go to this link
}
else {
//conn
$conn = mysql_connect("localhost", "k0m0d0", "ragnarok") or die(mysql_error());

//select db
mysql_select_db("ebay",$conn) or die(mysql_error());

//statement
$sql = "SELECT Source FROM auctions WHERE ID = '$AuctionID'";

//if script
$result = mysql_query($sql, $conn) or die(mysql_error());
if (mysql_num_rows($result) ==1) {

//fetch results
$row = mysql_fetch_array($result);

//extract is into the echo
extract($row);

echo "$Source";
};
};
?>
[/code]


Here is the page that has the link on (Click here to view) is the bit

[code=php]
<?PHP

//conn
$conn = mysql_connect("localhost", "k0m0d0", "ragnarok") or die(mysql_error());

//select db
mysql_select_db("ebay",$conn) or die(mysql_error());

//statement
$sql = "SELECT AuctionID, WinnerUserID FROM itemswon WHERE WinnerUserID =
'$_POST[eBayUserID]' AND eBayItemNumber = '$_POST[eBayItemNumber]'";

//if script
$result = mysql_query($sql, $conn) or die(mysql_error());
if (mysql_num_rows($result) ==1) {

//fetch results
$row = mysql_fetch_array($result);

//extract is into the echo
extract($row);

//new sql statement
$sql2 = "SELECT Title, SubTitle FROM auctions WHERE ID = '$AuctionID'";

//run the query
$result2 = mysql_query($sql2, $conn) or die(mysql_error());
if (mysql_num_rows($result2) ==1) {

//fetch results
$row2 = mysql_fetch_array($result2);

//extract is into the echo
extract($row2);

//display HTML
echo "<html>";
echo "<head>";
echo "<title>Untitled Document</title>";
echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">";
echo "</head>";
echo "";
echo "<body>";
echo "<form name="next" action="main.php">";
echo " <p><strong>$WinnerUserID</strong> Congratulations on winning";
echo " <br><strong>$Title</strong>";
echo " <br><strong>$SubTitle</strong></p>";
echo " <p><a href="source.php" target="_blank">Click here to view your item</a></p>";
echo " <p>This will take you through a few questions so APC-CompuNET can gain all of your details we need. No Payment is required through us direct and the payment options are stated in the eBay auctions, and again at the end of this registration. </p>";
echo " <p>";
echo " <input name="Next" type="image" id="Next" src="k" border="0">";
echo " </p>";
echo "</form>";
echo "</body>";
echo "</html>";
}

// If the eBayItemNumber dont exist
} else {
echo "You";
}
?>
[/code]


Thanks alot i rly appreciate this
Copy linkTweet thisAlerts:
@k0r54authorAug 13.2004 — am i doin this right? coz if i am it aint working lol
Copy linkTweet thisAlerts:
@shimonAug 13.2004 — If I'm reading this correctly, $_POST and $_SESSION are entirely irrelevant. Am I right in thinking you have a variable in one page that you want to pass on to another?

In which case your link looks like:[code=php]<a href="source.php?AuctionID=44" target="_blank">Click here to view your item</a>[/code]
Obviously, substitute '44' with the relevant number. Then in the script whcih 'receives' this click, you just need to read it in from the query string:
[code=php]<?php

$AuctionID = $_GET['AuctionID'];

?>[/code]
simple as ?
Copy linkTweet thisAlerts:
@k0r54authorAug 13.2004 — ok that is excellent, Thats very much
Copy linkTweet thisAlerts:
@NogDogAug 13.2004 — Should you decide you want to go the session route, [i]each[/i] page needs to have a [b]session_start()[/b] (prior to any output).

page1.php:
&lt;?php
session_start();
$_SESSION['test'] = "This is a test";
header("Location: page2.php");
?&gt;

page2.php:
&lt;?php
session_start();
echo "&lt;html&gt;&lt;head&gt;&lt;title&gt;Test&lt;/title&gt;&lt;/head&gt;&lt;body&gt;n";
echo "&lt;p&gt;$_SESSION['test']&lt;/p&gt;n";
echo "&lt;/body&gt;&lt;/html&gt;n";
?&gt;
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...