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
https://forums.phpfreaks.com/topic/56122-sql-syntax-error/
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
https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277220
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
https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277229
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
https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277247
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
https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277282
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
https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277307
Share on other sites

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.