DJTim666 Posted July 8, 2007 Share Posted July 8, 2007 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 https://forums.phpfreaks.com/topic/58980-carrying-a-variable/ Share on other sites More sharing options...
aim25 Posted July 8, 2007 Share Posted July 8, 2007 Use sessions. Link to comment https://forums.phpfreaks.com/topic/58980-carrying-a-variable/#findComment-292688 Share on other sites More sharing options...
rameshfaj Posted July 9, 2007 Share Posted July 9, 2007 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 https://forums.phpfreaks.com/topic/58980-carrying-a-variable/#findComment-292899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.