Jump to content

Carrying a variable


DJTim666

Recommended Posts

I need to know how to carry a variable from one action to the next.

 

<?php

require_once("database.php");
require_once("layout.php");

echo "<h3>Profiles</h3>";

if (!isset($_POST['username'])){
echo "<form action='profile.php' method='post'>
<input type='text' name='username' /><br>
<input type='submit' value='Search' />
</form>";
}

if (isset($_POST['username'])){
$username = mysql_real_escape_string($_POST['username']);
$sql = "SELECT * FROM users WHERE username='$username'";
$result= mysql_query($sql) or die(mysql_error());
$id = mysql_fetch_array($result) or die(mysql_error());

if (empty($username)){
	echo "You left the search field blank.";
	die();
}
if (mysql_num_rows($result) == 0){
	echo "That username does not exist in our database.";
	die();
}
else {
	echo "You are searching for the username " . $username . "<br /><br />";
	echo "<a href='$PHP_SELF?profile=" . $id['id'] . "'>" . $username . "</a>";
}
}

if ($_GET['profile']){
global $id, $username, $sql, $result;
$sql2 = "SELECT * FROM users WHERE id='$id'";
$result2 = mysql_query($sql2);
$fetch = mysql_fetch_array($result2);

echo "Username: " . $username . "<br>
ID: " . $fetch['id'] . "<br>
RP: " . $fetch['rp'] . "<br>
you can put more stuff
";
}

?>

 

When I click the link of the name i am searching it displays the profile but not the values.

 

So it displays;

 

Username:

ID:

RP:

you can put more stuff

 

I want it to display;

 

Username: Test

ID: 4

RP: 245256

you can put more stuff

 

Help is greatly appreciated.

 

--

DJ

Link to comment
Share on other sites

If u are using the href link then use like this:

 

$name='ramesh';

<a href="secondpage.php?name=$name">Go to nextPage</a>

 

Now in the second page if u use

$name =$_GET['name'];

then u will get the value "ramesh" in the $name variable in the second page.Dont forget to set the action of the first page to the second page.

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.