Jump to content

php to run an sql by accepting user input


kalid24

Recommended Posts

HI,

 

this coding is killing me and I'm sure it is something really simple. I am still learning PHP so please be nice!

 

I have created a database in mysql (1 table ) with about 5 columns, I am trying to write a php script that will perform an sql query but based on the input a user puts in to search.

 

 

<form action="<?PHP echo $_SERVER['PHP_SELF'];?>">

<p><b>

<label for="domain">filter:</label>

</b>

<input type="text" name="filter" id="filter" value="<?PHP echo $_REQUEST['filter'];?>">

</p>

</form>

 

 

<?PHP

 

Include "DB-connect.php";

 

//connection to the database

$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");

echo "Connected to MySQL<br>";

 

if(isset($_REQUEST['filter']))

{

// do somthing with value: $_REQUEST['filter']

// somthing like

$result = mysql_query("SELECT * FROM ".$db_name."severity_matrix WHERE 'network'= '".$_REQUEST['filter']."'");

//fetch tha data from the database

while ($row = mysql_fetch_array($result)) {

echo "link:".$row{'link'}." network:".$row{'network'}."line_rate: ". $row{'line_rate'}."<br>";

}

 

 

}

else

{

echo "no data found.";

}

//close the connection

mysql_close($dbhandle);

?>

 

 

-----------------------

 

When i load the script it shows the filter test with a text box for me to enter a search in and below it says connected my mySQL, no data found before I even get to search. That said, when i search a text that I know exists in the table under column 'network' it does not give me anything back, not even the "no data found" as per the loop.

 

Please help!!!! :(

i think your problem is at your query:

$result = mysql_query("SELECT * FROM ".$db_name."severity_matrix WHERE 'network'= '".$_REQUEST['filter']."'");

 

after FROM the column name should be indicated, which is I suppose severity_matrix. Unless all your column name's start which the database name?

 

where is this $db_name btw initialised? Also, what's in your DB-connect.php? since you make your connection under the include.

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.