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 Quote Link to comment Share on other sites More sharing options...
aim25 Posted July 8, 2007 Share Posted July 8, 2007 Use sessions. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.