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!!!! :(

Link to comment
Share on other sites

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.

Edited by stijn0713
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.