Forum Moderators: coopster
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!
For instance a form written as such:
<FORM METHOD="POST" ACTION="test.php">could be submitted to "test.php". Then each field can be used by the script like:
<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>
<?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