aMOEBa Posted June 19, 2010 Report Share Posted June 19, 2010 Hi geeks, I am working on a query string but I am kinda stuck with the code, I guess this is so cos am a PHP beginner. I want my script to display members list from a table in my db and attach a hyperlink to it so that when a user clicks on the link, it takes him to the full details of that member. So far, I have been able to retrieve data from db and attached links but when I click on the link,it just adds a member ID to the query string and it does not take u to page with full member details. What I have wirtten so far is shown below: <?php //connection.php /*$id = $_GET['id'];*/ $conn = mysql_connect($host, $user, $pass); $selDB = mysql_select_db($db); $sql = "select count(*) from info"; $result = mysql_query($sql); $row = mysql_fetch_row($result); $numRows = $row[0]; /*if (isset($_GET['id'])){ $id = (int)$_GET['id']; }*/ $sql = "select * from info"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ ?> <table> <td><?php echo stripslashes($row['name']). " ";?><a href="<?php echo $_SERVER['PHP_SELF']?>?id=<?php echo $row['id'];?>">[View Details]</a> </td> </tr> <?php } ?> Guys please help me out. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted June 19, 2010 Report Share Posted June 19, 2010 Seems like you could do something like this: <?php if (isset($_GET['id'])) { // add code here to process the id (make sure that the id is valid and isn't a hack attempt) and get the user's info from the database echo "user id is: " . $_GET['id']; } else { // display all the members with links to their detail's pages } ?> I actually put together two demos that cover this sort of functionality here: http://www.killersites.com/community/index.php?/topic/3064-basic-php-system-view-edit-add-delete-records-with-mysqli/'>http://www.killersites.com/community/index.php?/topic/3064-basic-php-system-view-edit-add-delete-records-with-mysqli/ http://www.killersites.com/community/index.php?/topic/1969-basic-php-system-vieweditdeleteadd-records/ The two are pretty similar, but the first uses MySQLi (often called MySQL Improved) which is more secure than traditional MySQL with support for prepared statements, which prevent SQL injection, a common security issue. I also did a couple part screencast series called "CRUD Basics With MySQLi & PHP" that covers how I built http://www.killersites.com/community/index.php?/topic/3064-basic-php-system-view-edit-add-delete-records-with-mysqli/ that's available on the KillerSites University (http://www.killersites.com/university - subscription required) within PHP > PHP CRUD Videos. Quote Link to comment Share on other sites More sharing options...
bishwadeep Posted June 30, 2010 Report Share Posted June 30, 2010 Hi, Create a memberdetails.php page and then copy and paste the following code. Then modify according to your requirement. <?php //connection.php /*$id = $_GET['id'];*/ $conn = mysql_connect($host, $user, $pass); $selDB = mysql_select_db($db); $sql = "select count(*) from info"; $result = mysql_query($sql); $row = mysql_fetch_row($result); $numRows = $row[0]; /*if (isset($_GET['id'])){ $id = (int)$_GET['id']; }*/ $sql = "select * from info"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ ?> <table> <td><?php echo stripslashes($row['name']). " ";?> <a href="memberdetails.php?id=<?php echo $row['id'];?>">[View Details]</a> </td> </tr> <?php } ?> memberdetails.php page <?php //memberdetails.php page $id=addslashes($_GET['id']); $sql = "select * from info WHERE id='".$_GET['id']."'"; $result = mysql_query($sql); $row=mysql_fetch_assoc($result); //now display the details in this page as the details are carried in the $row variable. ?> 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.
Note: Your post will require moderator approval before it will be visible.