I’ve tried to show the errors, and it doesn’t return anything. Here is my restructured code:
[php]<?php
// include function files for this application
require_once(‘bookmark_fns.php’);
session_start();
//create short variable names
$email = $_POST[‘email’];
$password = $_POST[‘password’];
if ($email && $password)
// they have just tried logging in
{
try
{
login($email, $password);
// if they are in the database register the user id
$_SESSION[‘valid_user’] = $email;
}
catch(Exception $e)
{
// unsuccessful login
do_html_header(‘Problem:’);
echo ‘You could not be logged in.
You must be logged in to view this page.’;
do_html_url(‘login.php’, ‘Login’);
do_html_footer();
exit;
}
}
error_reporting(“E_ALL”);
do_html_header();
if ($_SESSION['valid_user'])
{
display_user_menu();
check_valid_user();
}
?>
<?php
$id=$_GET['id'];
$lastname=$_GET['name'];
$license=$_GET['license'];
@ $db = new mysqli('localhost','smurf','hapuna32','silverskye_com_-_main');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$info = "select * from contractors where id = ".$id."";
$total = $db->query($info);
$line = $total->fetch_assoc();
echo'<h3>Contractor Name: <font color="#3333FF">'.$line['firstname'].' '.$line['lastname'].'</font></h3>
License Number: '.$line['license'].'<br>
<table border="0">
<tr>
<td>Address:</td><td> '.$line['address'].'</td></tr><tr>
<td> </td><td> '.$line['city'].', '.$line['state'].' '.$line['zipcode'].'
</td>
</tr>
</table><p>';
$query2 = "select avg(rating) as rating from contractors where license = ".$license."";
$res = mysql_db_query('silverskye_com_-_main', $query2);
$average = mysql_result($res, 1);
echo 'Average Rating: '.$average.'<p>';
$query = "select comments, rating, email from contractors where license = ".$license."";
$result = $db->query($query);
$num_results = $result->num_rows;
echo '<table cellpadding="3" cellspacing="1" border="0" bgcolor="#666666" width="620">
<tr>
<td bgcolor="#D2DBF6">Contractor Feedback</td>
</tr>';
for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
echo'<tr><td bgcolor="#FFFFFF"><strong>Posted By:</strong> <a href="mailto:'.$row['email'].'">'.$row['email'].'</a><br /><strong>Contractor Rating:</strong> '.$row['rating'].'<p>
<strong>Comments: </strong>'.$row['comments'].'</td></tr>';
}
echo '</table>';
echo '<p style="margin-top: 30px;"><strong>Add Comments About This Contractor</strong><p>
<form action="submitcontractor.php" method="post">
<input type="hidden" name="firstname" value="'.$line['firstname'].'">
<input type="hidden" name="lastname" value="'.$line['lastname'].'">
<input type="hidden" name="license" value="'.$line['license'].'">
<input type="hidden" name="address" value="'.$line['address'].'">
<input type="hidden" name="city" value="'.$line['city'].'">
<input type="hidden" name="state" value="'.$line['state'].'">
<input type="hidden" name="zipcode" value="'.$line['zipcode'].'">
<input type="hidden" name="user_email" value="'.$_SESSION['valid_user'].'">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top">Comments: </td><td colspan="2"><textarea name="comments" rows="6" cols="40"></textarea></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td>Rating: </td>
<td colspan="2">1<input type="radio" name="rating" value="1"> 2<input type="radio" name="rating" value="2"> 3<input type="radio" name="rating" value="3"> 4<input type="radio" name="rating" value="4"> 5<input type="radio" name="rating" value="5"> 6<input type="radio" name="rating" value="6"> 7<input type="radio" name="rating" value="7"> 8<input type="radio" name="rating" value="8"> 9<input type="radio" name="rating" value="9"> 10<input type="radio" name="rating" value="10">
</td>
</tr>
<tr>
<td> </td><td align="left" style="font-size: 10px;">Worst</td><td align="right" style="font-size: 10px;">Best</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Submit"></form></td>
</tr>
</table>';
$result->free();
$db->close();
do_html_footer();
?>[/php]
Here is the html page being displayed:
http://ww.silverskye.com/feedback/contractor.php?id=14&name=Taylor&license=89234293523
If you look at the page, everything works except for the average. It shows up blank. I ran the query in php my admin and it worked fine, so I’m not sure what is still wrong. Any help?
Admin Edit: Changed CODE tags to PHP for syntax highlighting. Additionally removed COLOR tags from code section. Both the CODE and PHP tags do not allow other phpBB tags inside the CODE and PHP tags (respectively). The CODE and PHP tags are akin to the tags in html except that the PHP tags allow for PHP Syntax highlighting.