Jump to content

[SOLVED] Something wrong with my sql?


Jewbilee

Recommended Posts

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

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());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.