Jump to content

PHP and MySQL Question/Help


jefffogel1974

Recommended Posts

I have a MySQL db with all my servers and all their details like server name, IP, OS, RAM etc etc 26 in total. I have a PHP page which will list all server names with a link on the page and when you click the link its suppose to go to a page that is called serverdetails.php which it does, but how do I only list information from the one server of the link I clicked on? Below is the code I am using to go to the next page.

 

echo "<A HREF=\"http://vm-webdev/serverdetails?svr={$row['Server_Name']}\">{$row['Server_Name']}</A><br>";

Link to comment
Share on other sites

Hi jefffogel1974,

 

You would need to perform a MySQL Query on serverdetails.php which will use the server name (assuming $row['Server_name'] is unique) and perform a WHERE statement.

 

For example:

 

<?php
//This make_safe() function sanitises anything passed to it - ideal for $_GET and $_POST values
function make_safe($unsafe)
{
require("connect/config.inc.php");
$safe = mysql_real_escape_string(strip_tags(trim($unsafe)));
return $safe;
}

$sql = mysql_query("SELECT * FROM yourtable WHERE servername = '".make_safe($_GET['svr'])."' ORDER BY id");

 

If $row['Server_Name'] is not unique, you would need to do the above but using the auto-incrementing id each row has, as this is always unique.  Obviously, your link code would need to be amended accordingly, i.e.:

 

echo "<A HREF=\"http://vm-webdev/serverdetails.php?id={$row['id']}\">{$row['Server_Name']}</A><br>";

 

The MySQL query would then need to read something like:

 

$sql = mysql_query("SELECT * FROM yourtable WHERE id = '".make_safe($_GET['id'])."' ORDER BY id");

 

Hope this helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.