The aim
The user enters inserts a number into a text field and hits calculate
That number is then subtracted by 250
Depending on what the $result is, a particular image is shown.
The problem
When the page is run I get the following error message;
Catchable fatal error: Object of class mysqli_result could not be converted to string in /home/cs12jcw/public_html/n-power/includes/calculator.php on line 95
Line 95 is;
echo "<img src='$image' alt='' />";
The full code
<?php
$valuea = (isset($_POST['valuea']) && is_numeric($_POST['valuea'])) ? $_POST['valuea'] : 0;
$valueb = 250;
$answer = $valuea - $valueb;
?>
<form method='post' action='calculator.php'>
<table border='0' width='500px' cellpadding='3' cellspacing='1' class="table">
<tr class="calcheading">
<td colspan="2"><strong>Work out how much you could be saving</strong></td>
</tr>
<tr class="calcrow">
<td>How much do you spend a year?</td>
<td align="center"><input type='text' name='valuea' value="$valuea"/></td>
</tr>
<tr class="calcrow">
<td>Minus the average price of an n-power student tarrif* Leave Blank:</td>
<td align="center"><input type='text' name='valueb' value="$valueb"/></td>
</tr>
<tr class="submit">
<td colspan="2"><input type='submit' value='Calculate'/></td>
</tr>
<tr class="calcrow">
<td><i>You could be saving:</td>
<td align="center"><input type="text" value="<?php echo round($answer)?>"></td></i>
</tr>
</table>
</form>
<?php
if($db_server){
switch( $answer ){
case $answer > 0 and $answer < 150 : $image = mysqli_query($db_server, "SELECT URL FROM images WHERE imagename = 'image1'");
break;
case $answer < 250 : $image = mysqli_query($db_server, "SELECT URL FROM images WHERE imagename = 'image2'");
break;
case $answer < 350 : $image = mysqli_query($db_server, "SELECT URL FROM images WHERE imagename = 'image3'");
break;
case $answer < 450 : $image = mysqli_query($db_server, "SELECT URL FROM images WHERE imagename = 'image4'");
break;
case $answer < 550 : $image = mysqli_query($db_server, "SELECT URL FROM images WHERE imagename = 'image5'");
break;
}
echo "<img src='$image' alt='' />";
}
?>
Please let me know if you need anything else. Apologies if I've missed anything.