Jump to content

SQL Syntax error


franknu

Recommended Posts

ok i am getting a syntax error on my query here it is

 

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 'business_info.BusinessName, messages.BusinessName FROM busines_info INNER JOIN m' at line 1

 

and here is my code

 


<?


if( isset($BusinessName))
{
$sql= "SELECT *  business_info.BusinessName, messages.BusinessName FROM busines_info INNER JOIN messages 
WHERE BusinessName= '".$_SESSION['BusinessName']."' "; 
mysql_query($sql) or die(mysql_error());
$result=mysql_query($sql);
}

if ($result = mysql_query($sql)) 
{
  if (mysql_num_rows($result))
{
      $row = mysql_fetch_assoc($result);
      $BusinessName= $row['BusinessName'];
      $date = $row['date'];
      $from =  $row['from'];
      $subject = $row['subject'];
      $message =$row['message'];
  }
else 
{
      echo "Query failed<br />$sql<br />". mysql_error();

exit;

}
}


?>

Link to comment
Share on other sites

INNER is not the answer because he was trying to use the normal join

your code is SELECT *  business_info.BusinessName, messages.BusinessName FROM busines_info INNER JOIN messages

WHERE BusinessName= '".$_SESSION['BusinessName']

 

change this to

 

SELECT *  business_info.BusinessName, messages.BusinessName FROM busines_info,messages

 

note this line should be a joinning procedure

WHERE BusinessName= '".$_SESSION['BusinessName']

 

 

so it should be

SELECT *  business_info.BusinessName, messages.BusinessName FROM busines_info,messages

WHERE business_info.BusinessName=messages.BusinessNameBusiness and Name= '".$_SESSION['BusinessName'];

 

hope that helps

 

Link to comment
Share on other sites

Ok, i made some changes and here is my new code

 


if( isset($BusinessName))
{
$sql=" SELECT *  business_info.BusinessName, messages.BusinessName FROM business_info,messages
WHERE business_info.BusinessName=messages.BusinessName AND BusinessName= '".$_SESSION['BusinessName']."' ";

mysql_query($sql) or die(mysql_error());
$result=mysql_query($sql);
}

 

here is my display

 

 

 

error

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 'business_info.BusinessName, messages.BusinessName FROM business_info,messages W' at line 1

Link to comment
Share on other sites

$sql=" SELECT  business_info.BusinessName, messages.BusinessName FROM business_info,messages

WHERE business_info.BusinessName=messages.BusinessName AND BusinessName= '".$_SESSION['BusinessName']."' ";

 

remove the askterisk

 

Link to comment
Share on other sites

ok, i am getting this now never seen it before

 

Column 'BusinessName' in where clause is ambiguous

 

Based on the rest of the query, BusinessName exists in two database tables.  The WHERE clause doesn't know whether you want to use BusinessName from business_info or business_messages ... so it's ambiguous.  You need to define which database table to use.

Link to comment
Share on other sites

that didnt work 

 

Here is my code

<?


$sql=" SELECT   messages.* FROM business_info,messages
WHERE business_info.BusinessName=messages.BusinessName";

mysql_query($sql) or die(mysql_error());
$result=mysql_query($sql);


if ($result = mysql_query($sql)) 
{
  if (mysql_num_rows($result))
{
      $row = mysql_fetch_assoc($result);
      $BusinessName= $row['BusinessName'];
      $date = $row['date'];
      $from =  $row['from'];
      $subject = $row['subject'];
      $message =$row['message'];
  }
else 
{
      echo "Query failed<br />$sql<br />". mysql_error();

exit;

}
}


?>

 

Link to comment
Share on other sites

<?php

$sql=" SELECT  messages.* FROM business_info,messages

WHERE business_info.BusinessName=messages.BusinessName";

$result=mysql_query($sql);

while($row=mysql_fetc_assoc($result))

{

      $BusinessName= $row['BusinessName'];

      $date = $row['date'];

      $from =  $row['from'];

      $subject = $row['subject'];

      $message =$row['message'];

 

  }

 

?>

 

note try to query this in your db if it works  the the above code will surely run

SELECT  messages.* FROM business_info,messages

WHERE business_info.BusinessName=messages.BusinessName

Link to comment
Share on other sites

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.