Receiving Fatal Error with PHP Code

Hi Everyone,

I manage a car dealership website, and I have the pre-owned inventory displaying from a database. I updated the database, then went to the page, and nothing showed up. After modifying the database connect code, I am now receiving a fatal error for code that looks correct and WAS working up until now. I already contacted my hosting support, and they said the error is in the code. Can anyone help?

Here is the error: Fatal error: Call to a member function on a non-object in /home/dadejeep/public_html/searchpreowned.php on line 122

Here is the code:

[code]
$make=$_POST[‘make’];
$model=$_POST[‘model’];

$conn = mysql_connect(‘localhost’, ‘dadejeep_site’, ‘*****’, ‘dadejeep_cars’) or die
‘Error connecting to mysql’);

if (!$make)
{
$query1 = “select * from usedcars order by year desc”;
$result = $conn->query($query1);

} else {

            switch ($model)
		{
		        case "all": 
			           $query2 = "select * from usedcars where make='$make' order by year desc";
				   $result = $conn->query($query2);
							
			break;
							
			case "certified":
				$query3 = "select * from usedcars where certified='yes'";
				$result = $conn->query($query3);
							
			break;
						
			default:
				$query4 = "select * from usedcars where make='$make' and model='$model' order by year desc";
				$result = $conn->query($query4);
							
			break;
		}
	}
				
	$num_results = $result->num_rows;
					
	echo 'Search for:<strong> '.$make.' '.$model.'</strong><p>Number of Results Found:<strong> '.$num_results.'</strong><p>';
					
	echo ' <table cellpadding="3" cellspacing="1" border="0" bgcolor="#666666" width="744">
			<tr>
				<td bgcolor="#D2DBF6">Result</td>
                                    <td bgcolor="#D2DBF6">Image</td>
                                    <td bgcolor="#D2DBF6">Year</td>
                                    <td bgcolor="#D2DBF6">Make</td>
                                    <td bgcolor="#D2DBF6">Model</td>
                                    <td bgcolor="#D2DBF6">Color</td>
                                    <td bgcolor="#D2DBF6">Miles</td>
                                    <td bgcolor="#D2DBF6">VIN</td>
                                    <td bgcolor="#D2DBF6">Stock Number</td>
                                    <td bgcolor="#D2DBF6">Certified</td>
			</tr>';
					
			for ($i=0; $i <$num_results; $i++)    {
				$row = $result->fetch_assoc();
				echo' <tr><td bgcolor="#FFFFFF">'.($i+1).'</td>';
				echo'<td bgcolor="#FFFFFF"><a href="/preowned.php?stockno='.$row['stockno'].'"><img src="'.$row['thumbnail'].'" style="border: 1px; border-style: solid; border-color: #000000;"></a></td>';
				echo'<td bgcolor="#FFFFFF">'.$row['year'].'</td>';
				echo'<td bgcolor="#FFFFFF">'.$row['make'].'</td>';
				echo'<td bgcolor="#FFFFFF">'.$row['model'].'</td>';
				echo'<td bgcolor="#FFFFFF">'.$row['color'].'</td>';
				echo'<td bgcolor="#FFFFFF">'.$row['miles'].'</td>';
				echo'<td bgcolor="#FFFFFF"><a href="/preowned.php?stockno='.$row['stockno'].'" style="text-decoration: underline;">'.$row['vin'].'</a></td>';
				echo'<td bgcolor="#FFFFFF">'.$row['stockno'].'</td>';
				echo'<td bgcolor="#FFFFFF">';
				
                                  switch ($row['certified']) {
					case "yes":
						echo '<img src="/images/certified2.jpg"></div>';
					break;
										
					default:
					        echo '<br>';
					break;
					}
					echo '</td></tr>';
				}
					
		$result->free();
		$conn->close();[/code]

Thanks,
Jen

I only see 80 lines there, so I can’t tell what’s on line 122. Is this the page searchpreowned.php?

Oh my apologies. The code is breaking here:

$result = $conn->query($query1);

Thanks,
Jen

$conn is not an object there ;) It’s a resource handle for a MySQL connection. You’re going to have to do something like this:

$result = mysql_query($query1, $conn);
Sponsor our Newsletter | Privacy Policy | Terms of Service