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
https://forums.phpfreaks.com/topic/178345-php-and-mysql-questionhelp/
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.

Archived

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

×
×
  • 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.