-
The $_GET variable
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>";
}
?>
-
I think it work ok, but in my opinion this is not really a good way.
If i were you, I will use POST method to avoid posting variable to address
Btw, you should print some thing when there is no username match $_GET['username'], kind da like: User name ABC not found or st :)
-
-
Quote:
Originally Posted by
topsitex
what is '%s' ?
joining the question .
-
-
No i dont thinks so...
%s?! you mine:
printf("<a href='secondpage.php?username="".$row['username'].""'>".$row['username']."</a>"."<br/>");
get the info by _POST
-
i love PHP:rolleyes::grin::grin::grin: its lots of fun and really cool.