I am trying to get values from firstpage.php and send them to secondpage.php this is what i have figured out and i am wondering if it is the correct way to do it thanks.
Firstpage.php
PHP Code:
<?php
//Connects to the database.
$con = mysql_connect("localhost","blank","blank") or die (mysql_error());
$db = mysql_select_db("wsdatabase") or die (mysql_error());
// Selects username's from the user table.
$sql = "select username from users";
$query = mysql_query($sql);
// List's every name in the table with a link going to the secondpage.php.
while($row = mysql_fetch_array($query)) {
printf("<a href='secondpage.php?username=%s'>%s</a>"."<br/>",$row['username'],$row['username']);
}
?>
secondpage.php
PHP Code:
<?php
// Grabs the username with the get method.
if(isset($_GET['username'])) {
$username = $_GET['username'];
}
// Connects to the database.
$con = mysql_connect("localhost","blank","blank") or die (mysql_error());
$db = mysql_select_db("wsdatabase") or die (mysql_error());
// Selects everything from the database.
$sql = "select * from users where username = '$username' ";
$query = mysql_query($sql);
// Prints everything out from the database.
while($row = mysql_fetch_array($query)) {
echo "<b>".$row['title']."</b>";
echo "<br/>";
echo "<b>".$row['username']."</b>";
echo "<br/>";
echo "<b>".$row['email']."</b>";
}
?>
Bookmarks