All,
I am having a TERRIBLE time trying to figure out how to appropriately use variables in my php. I figured out how to pass a variable to a SELECT statement using a URL, but how in the heck do I pass a variable to a SELECT statement that is defined later in the PHP file. Here is my code:
<html>
<head>
<body>
<?php
$username = "user";
$passsword = "password";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, "l0urd3s")
or die("Unable to connect to Prelude Correlation database");
print "Connected to Correlation database<p>";
$selected = mysql_select_db("prelude",$dbh)
or die("Could not select Correlation database");
// Get Correlation Data from Database //
$query="SELECT * FROM Prelude_CorrelationAlert_Alerts";
$result=mysql_query($query);
$num=mysql_numrows($result);
// grab the IDENT from the database to use as the variable //
$desc_id="1";
$desc="SELECT * from Prelude_CorrelationAlert where ident=".$desc_id." limit 1";
$result2=mysql_query($desc);
mysql_close();
// BEGIN DISPLAYING OUR HTML //
echo "<b><center>Database Output</center></b><p>";
echo "
<table width=800 cellpadding=4 cellspacing=0 bordercolor=#000000 border=1>
<tr bgcolor=eaeaea>
<td width=200><b>Ident</b></td>
<td width=200><b>Correlated Alert</b></td>
<td width=200><b>Alert ID</b></td>
</tr><tr>";
$i=0;
while ($i < $num){
$ident=mysql_result($result,$i,"ident");
$alert_ident=mysql_result($result,$i,"alert_ident");
$name2=mysql_result($result2,$i,"name");
echo "
<td valign=top width=200><font size=1 face=verdana>$ident</td>
<td valign=top width=200><font size=1 face=verdana>$name2</td>
<td valign=top width=200><font size=1 face=verdana><a href=packet.php?aid=$alert_ident>$alert_ident</a></td>
</tr><tr>";
++$i;
}
?>
Every other column except $name2 prints fine.. Thisis what I get in my web browser:
Ident Correlated Alert Alert ID
1 Source correlation (period=86400 sec) by prelude-correlation-agent 265858
Warning: mysql_result(): Unable to jump to row 1 on MySQL result index 4 in /usr/local/apache/htdocs/prelude/piwi/correlation/correlation.php on line 46
1 265859
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 4 in /usr/local/apache/htdocs/prelude/piwi/correlation/correlation.php on line 46
1 265860
Warning: mysql_result(): Unable to jump to row 3 on MySQL result index 4 in /usr/local/apache/htdocs/prelude/piwi/correlation/correlation.php on line 46
1 265861
Warning: mysql_result(): Unable to jump to row 4 on MySQL result index 4 in /usr/local/apache/htdocs/prelude/piwi/correlation/correlation.php on line 46
1 265862
Warning: mysql_result(): Unable to jump to row 5 on MySQL result index 4 in /usr/local/apache/htdocs/prelude/piwi/correlation/correlation.php on line 46
Someone please help me with these variables.. I want to start SELECTING specific information from all sorts of diffferent tables in my database, so once I figure out how to do it with this, I can do others.