Jump to content

select users id with method GET


loonie35

Recommended Posts

i have table users and i want to view some other user and his information there listed in that page, something like user.php?id=userid
If you did it that way, you'd find the user ID here: $_GET['id']Is your DB mysql? Do you need help with that? What's the name of the column that holds the user ID?
Link to comment
Share on other sites

I have MySQL here is my table conents

CREATE TABLE `users` (  `id` int(255) NOT NULL auto_increment,  `username` varchar(255) collate utf8_latvian_ci NOT NULL,  `age` varchar(255) collate utf8_latvian_ci NOT NULL,  `picture` varchar(255) collate utf8_latvian_ci NOT NULL,  PRIMARY KEY  (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_latvian_ci AUTO_INCREMENT=3;

I tryed to make something like that:

$id = $_GET['userid'];	if (isset($_GET['id']) and $_GET['id'] == "$id")	{		$r = mysql_query("SELECT * FROM users");		while ($row = mysql_fetch_assoc($r)) {		echo $row['username'];		};	}

but just shows blank page.

Link to comment
Share on other sites

I adapted this from the PHP manual. You'll need to change the values to make the correct connection and select the correct database..

$conn = mysql_connect("localhost", "mysql_user", "mysql_password");if (!$conn) {	echo "Unable to connect to DB: " . mysql_error();	exit;} if (!mysql_select_db("mydbname")) {	echo "Unable to select mydbname: " . mysql_error();	exit;}$id = $_GET['id'];$sql = "SELECT * FROM users WHERE  id = $id";$result = mysql_query($sql);if (!$result) {	echo "Could not successfully run query ($sql) from DB: " . mysql_error();	exit;}if (mysql_num_rows($result) == 0) {	echo "No rows found, nothing to print so am exiting";	exit;}while ($row = mysql_fetch_assoc($result)) {	echo $row["id"];	echo $row["username"];	echo $row["age"];	echo $row["picture"];}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...