Forum Moderators: coopster

Message Too Old, No Replies

PHP/Mysql $_POST

         

rscrsc

8:47 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



Hello everyone I am having a hard time trying to figure out how to have to $_POST variables on a php page.

here is an example of my code. I am trying to have a user input both and Ip address and date which will get sent to a php page and used in the mysql query. How do I enter to variables in my mysql query.

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
//Query that is being run
$query= "select inet_ntoa(ip_src), inet_ntoa(ip_dst), layer4_sport, layer4_dport, timestamp, sig_name from acid_event where inet_ntoa(ip_src)= '" . $_POST['IP'] . "'";
//this will try to spit out the previous sql query
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
//this is a line break before the spit output
while ($line = mysql_fetch_row($result) )
{

this is the code with just the "IP" _POST varible that is being enter on the HTML page.

I have tried . $_POST['IP'] . "'", . $_POST['DATE'] . "'"; But it did not work. There is not much info online on mulitple POST commands.

How would I have $_POST['IP'] and $_POST['DATE'] in my mysql query.

thanks for all the help!

IamStang

3:16 am on Mar 24, 2006 (gmt 0)

10+ Year Member



$_POST is used to pass input from a form to the script. If you have a form in your html document that uses the "POST" method, you can submit as many fields to the scripts as you desire. So long as, generally speaking, they are all named uniquely.

For instance a form written as such:

<FORM METHOD="POST" ACTION="test.php">
<input type="text" name="field1" size="20">
<input type="text" name="field2" size="20">
<input type="text" name="field3" size="20">
<input type="text" name="field4" size="20">
<input type="text" name="field5" size="20">
<input type="submit" value="Submit">
</form>
could be submitted to "test.php". Then each field can be used by the script like:
<?PHP
$field1 = $_POST["field1"];
$field2 = $_POST["field2"];
$field3 = $_POST["field3"];
$field4 = $_POST["field4"];
$field5 = $_POST["field5"];

echo "$field1<br>$field2<br>$field3<br>$field4<br>$field5<br>";
?>

As for the users IP address. You can use your PHP script to get it automatically. (Keep in mind that IP addresses can be faked). Simply use:

$ip_addy = $_SERVER["REMOTE_ADDR"];
echo $ip_addy;

Same goes for the "Date". It can be set by your script automatically as well. Have a read through the PHP Date Manual [php.net] for more info on using it.

I hope the above is useful.

Regards,
IamStang