Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.