PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
include 'db.php';
//first open connection to your database
$takeuser = mysql_query("SELECT full_name FROM users LIMIT 5"); //Right now script check id number from url against the database
while ($row=mysql_fetch_array($takeuser)) { //Taking the result set
echo 'Name: ' . $row['full_name'] . '<br/><br/>';
} //closing the loop
mysql_close($link); //and then we close connection
?>
everything works and it shows the names of the people in the database but is there as way to also add a hyperlink to the name.
<?php
include 'db.php';
//first open connection to your database
$takeuser = mysql_query("SELECT full_name FROM users LIMIT 5"); //Right now script check name from url against the database
while ($row=mysql_fetch_array($takeuser)) { //Taking the result set
echo 'Name: <a href="users.php?name=' . urlencode($row['full_name']) . '">' . $row['full_name'] . '</a><br /><br />';
} //closing the loop
mysql_close($link); //and then we close connection
?>
<?php
include 'db.php';
//first open connection to your database
$name = mysql_real_escape_string($_GET['name']); //catch the name from url, store it and escape slashes from possible attack.
$takeuser = mysql_query("SELECT * FROM users WHERE name='$name' LIMIT 5"); //Right now script check name from url against the database
if (mysql_num_rows($takeuser) < 1) { //checks if we have that name in our database
echo "Wrong Argument!"; //inform the user that we found 0 result
} else { //or if we found some
while ($row=mysql_fetch_array($takeuser)) { //Taking the result set
echo 'Name: ' . $row['full_name'] . '<br/>';
echo 'User: ' . $row['user_name'] . '<br/>'; //Displaying the result (ie you can have various fields in your table, display what you want)
echo 'E-mail: ' . $row['user_email'] . '<br/>';
} //closing the loop
} //closing the "if" statement
mysql_close($link); //and then we close connection
?>
Last edited by Benjamin on Wed Apr 29, 2009 7:33 pm, edited 2 times in total.
Reason:Changed code type from text to php.
tasairis wrote:Actually, don't. The server decodes everything for you, so if you decode it again then you can get the wrong results.
I guess that's what I get for not testing my code before I post it. Sorry about that.
PHP Manual: urldecode wrote:The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.
Edit: This post was recovered from search engine cache.