Forum Moderators: coopster

Message Too Old, No Replies

simple enough db query.can't see my error

         

RogueDogg

6:08 pm on Mar 6, 2008 (gmt 0)

10+ Year Member



I can't seem to see my error in my code. Maybe I've been looking at it too long or something.


<?PHP
//Define link to go back to
$backlink = "<br><br><a href='searchapprovals.html'><font size='-1' font color='#000000'>Do another Search CLICK HERE</font></a>";

//report errors
error_reporting(E_ALL);
//make connection
$db = mysql_connect("localhost", "dbuser", "dbpass");
if (!$db) {
die('Could not connect: ' . mysql_error());
exit();
}

//select DB
$db_selected = mysql_select_db("dbname", $db);
if (!$db_selected) {
die ('Can\'t connect to db : ' . mysql_error());
exit();
}

//select info from DB
$query = "SELECT * FROM dbname WHERE ID >= '0'";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
exit();
}

//if no results echo this message
if (mysql_num_rows($result) == 0){
echo "<br><br><table align='center'><tr><td><font color='#FF0000'>Sorry no results found using that criteria</font><br><br>$backlink</td></tr></table>";
exit();
}

while ($row=mysql_fetch_array($result)) {

?>

<h3 align="center"><font color="#3366FF" size="4" face="Arial, Helvetica, sans-serif">Approval DB Search</font></h3>
<table align="center" width="500" border="1" bordercolor="#000000">
<tr>
<td class="style1">CUID: <font color="#FF0000"><?PHP echo $row["CUID"];?></font></td>
<td><a href="http://www.example.com/mail/mail2.php?email=<?PHP =$row['Email']?>&First=<?PHP =$row['Fname']?>&Last=<?PHP =$row['Lname']?>">E-mail</a></td>
<td class="style1">&nbsp;</td>
</tr>
<tr>
<td class="style1"><?PHP echo $row["Fname"]." ".$row["Lname"];?> <font color="#FF0000">(First/Last Name)</font></td>
<td class="style1"><?PHP echo $row["Time"];?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="style1"><?PHP echo $row["IP"];?> <font color="#FF0000">(IP Address)</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="style1"><?PHP echo $row["Browser"];?> <font color="#FF0000">(Browser)</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="style1"><?PHP echo $row["Comment"];?> <font color="#FF0000">(Comment)</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="style1"><?PHP echo $row["Yes"];?> <?PHP echo $row["No"];?> <font color="#FF0000">(Approval)</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<?PHP
}
?>

The end result is a blank page no errros thrown. However if I comment out my DB query strings I see my html table, so the problem lies there I would say...?

whoisgregg

6:43 pm on Mar 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a little mixup with the shorthand notation "<?=" [us.php.net] which should be fixed and is probably causing the problem.

<?PHP =$row['Email']?>

And other similar calls should be:

<?php echo $row['Email']?>

RogueDogg

6:50 pm on Mar 6, 2008 (gmt 0)

10+ Year Member



wow..sometimes the things you end up overlooking...Thanks, that seems to have fixed it.

cheers :-)


<?=$row['Fname']?>

Also works ;-)

What'd you use for code to get the box around your example ?

[edited by: RogueDogg at 6:58 pm (utc) on Mar. 6, 2008]

whoisgregg

7:29 pm on Mar 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The short tag notation does work, but since it's off by default and it's going to be completely removed in a future release of PHP, it's best for all of us to get used to not having it. :)

I always use [ quote ][ code ][ /code ][ /quote ] (without spaces) for code blocks. I like how it looks. :D