Forum Moderators: coopster
A users is going to be inserting an IP address which will get put into a $POST variable which we are going to be using in the queries. We would like to search both databases for the IP and print out both results. Can someone help me out I am getting an error stating that [Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 31] line 31 is
while ($row = mysql_fetch_array($result) ).
thanks for the help.
//Connection to both MYSQL databases
$conn1 = mysql_connect($Dragon_host,$Dragon_user,$Dragon_pass) or die (mysql_errno().": ".mysql_error()."<BR>");
$conn2 = mysql_connect($Snort_host,$Snort_user,$Snort_pass) or die (mysql_errno().": ".mysql_error()."<BR>");
//mysql query that is going
//to be performed
$result = mysql_query("select datetime, sensor, signature, inet_ntoa(source), inet_ntoa(dest), sourceport, destport, protocols from dragon where inet_ntoa(source) like '" .$Drgsrc."' or inet_ntoa(dest) like '" .$Drgsrc."'", $conn1);
echo "connected successfully";
while ($row = mysql_fetch_array($result) )
{
$innerresult = mysql_query("select inet_ntoa(ip_src), inet_ntoa(ip_dst), layer4_sport, layer4_dport, timestamp, sig_name, sid, cid from acid_event where inet_ntoa(ip_src) like '" .$Src."' or inet_ntoa(ip_dst) like '" .$Src."'", $conn2);
echo '<tr>';
echo $row['rowname'];
echo '<td align="center">',$row['datetime'],'</td>';
echo '<td align="center">',$row['sensor'],'</td>';
echo '<td align="center">',$row['signature'],'</td>';
echo '<td align="center">',$row['inet_ntoa(source)'],'</td>';
echo '<td align="center">',$row['inet_ntoa(dest)'],'</td>';
echo '<td align="center">',$row['sourceport'],'</td>';
echo '<td align="center">',$row['sig_name'],'</td>';
On line 31 you are passing the value of $result to the function mysql_fetch_array()
A few lines avobe, you set the value of $result:
$result = mysql_query("select datetime, sensor, signature, inet_ntoa(source), inet_ntoa(dest), sourceport, destport, protocols from dragon where inet_ntoa(source) like '" .$Drgsrc."' or inet_ntoa(dest) like '" .$Drgsrc."'", $conn1);
Check that the name of the fields from your query match the names on your database. eg. inet_ntoa(source), inet_ntoa(dest) and so on.
Try running the query directly in Mysql command line to see if it returns the desired results.
As the error says, there is something wrong with the value of $result. If you double checked the query syntax
then the error must be in the value of $conn1.
$conn1 = mysql_connect($Dragon_host,$Dragon_user,$Dragon_pass) or die (mysql_errno().": ".mysql_error()."<BR>");
It is usally a little mistake or something you are not seeing...try swapping $conn1 and $conn2 for example. You might be sending the query to the wrong database.
Try this one:
//Connection
$conn1 = mysql_connect($Dragon_host,$Dragon_user,$Dragon_pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db('conn1_db_name', $conn1);
$conn2 = mysql_connect($Snort_host,$Snort_user,$Snort_pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db('conn2_db_name', $conn2);
//mysql query that is going
//to be performed
$result = mysql_query("select datetime, sensor, signature, inet_ntoa(source), inet_ntoa(dest), sourceport, destport, protocols from dragon where inet_ntoa(source) like '" .$Drgsrc."' or inet_ntoa(dest) like '" .$Drgsrc."'", $conn1);
echo "connected successfully";
while ($row = mysql_fetch_array($result) )
{
$innerresult = mysql_query("select inet_ntoa(ip_src), inet_ntoa(ip_dst), layer4_sport, layer4_dport, timestamp, sig_name, sid, cid from acid_event where inet_ntoa(ip_src) like '" .$Src."' or inet_ntoa(ip_dst) like '" .$Src."'", $conn2);
echo '<tr>';
echo $row['rowname'];
echo '<td align="center">',$row['datetime'],'</td>';
echo '<td align="center">',$row['sensor'],'</td>';
echo '<td align="center">',$row['signature'],'</td>';
echo '<td align="center">',$row['inet_ntoa(source)'],'</td>';
echo '<td align="center">',$row['inet_ntoa(dest)'],'</td>';
echo '<td align="center">',$row['sourceport'],'</td>';
echo '<td align="center">',$row['sig_name'],'</td>';