Jewbilee Posted June 12, 2007 Share Posted June 12, 2007 I have a code that for some reason is not working. I've printed out the sql error and it just says there's an error... nothing specific. The problem is with $query1. Its saying theres an error but ive run the query in PHPMyAdmin and it works fine. Any suggestions? <?php include("layout_1.txt"); include("connect.php"); $id = $_GET['id']; if(!empty($id)) { $query = "SELECT * FROM camprentals WHERE id=$id"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query1 = "SELECT * FROM rentalsgal"; $result1 = mysql_query(query1) or die ("Error in query: $query1. ".mysql_error()); while($row = mysql_fetch_object($result)) { echo "<center><font size=5>$row->title</font><br><br>"; $imgs = explode(" ", $row->imgs); echo "<table border=0 cellspacing=10>"; $count = 1; foreach($imgs as $value) { $found = false; while($row1 = mysql_fetch_object($result1)) { if($value == $row1->name) { $found = true; } } if($found){ if($count == 1) { echo "<tr><td>"; } else { echo "<td>"; } echo "<a href=\"gallery/rentals/".$value.".jpg\"><img src=\"gallery/rentals/".$value."_thumb.jpg\" border=0></a>"; if($count == 5) { echo "</td></tr>"; } else { echo "</td>"; } $count++; } } echo "</table>"; echo $row->desc; } } else { $query = "SELECT * FROM camprentals"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "<table border=0>"; while($row = mysql_fetch_object($result)) { $desc = substr($row->desc, 0, 150); echo "<tr><td width=\"110\"><img src=\"gallery/rentals/".$row->mainimg."_thumb.jpg\"></td> <td><font size=5><a href=\"rentals.php?id=$row->id\">$row->title</a> </font><br>".$desc."...</td></tr>"; } echo "</table>"; } include("layout_2.txt"); ?> Link to comment https://forums.phpfreaks.com/topic/55204-solved-something-wrong-with-my-sql/ Share on other sites More sharing options...
btherl Posted June 12, 2007 Share Posted June 12, 2007 Please post your error message Link to comment https://forums.phpfreaks.com/topic/55204-solved-something-wrong-with-my-sql/#findComment-272891 Share on other sites More sharing options...
Jewbilee Posted June 12, 2007 Author Share Posted June 12, 2007 Error in query: SELECT * FROM rentalsgal. You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'query1' at line 1 Link to comment https://forums.phpfreaks.com/topic/55204-solved-something-wrong-with-my-sql/#findComment-272901 Share on other sites More sharing options...
pocobueno1388 Posted June 12, 2007 Share Posted June 12, 2007 You are missing the dollar sign in your query... change this: $result1 = mysql_query(query1) or die ("Error in query: $query1. ".mysql_error()); To this: $result1 = mysql_query($query1) or die ("Error in query: $query1. ".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/55204-solved-something-wrong-with-my-sql/#findComment-272903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.