franknu Posted June 18, 2007 Share Posted June 18, 2007 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/ Share on other sites More sharing options...
AndyB Posted June 18, 2007 Share Posted June 18, 2007 Change ... FROM busines_info INNER ... to ... FROM business_info INNER Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277215 Share on other sites More sharing options...
teng84 Posted June 18, 2007 Share Posted June 18, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277220 Share on other sites More sharing options...
AndyB Posted June 19, 2007 Share Posted June 19, 2007 ... but I bet it still needs the name of the table correctly - business_info not busines_info Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277222 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 we dont know maybe thats how he write his own code lol When i was a new with programming i sometimes do my codes that way Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277224 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277229 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 $sql=" SELECT business_info.BusinessName, messages.BusinessName FROM business_info,messages WHERE business_info.BusinessName=messages.BusinessName AND BusinessName= '".$_SESSION['BusinessName']."' "; remove the askterisk Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277236 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 ok, i am getting this now never seen it before Column 'BusinessName' in where clause is ambiguous Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277238 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 i dont see it to hope you know whats next Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277240 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 well i deleted this AND BusinessName= '".$_SESSION['BusinessName']." from the end but then it is not selecting from the database Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277244 Share on other sites More sharing options...
AndyB Posted June 19, 2007 Share Posted June 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277247 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 business_info.BusinessName=messages.BusinessName check if these to fields that you are combining have what it takes to be joined Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277248 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 they do have the same value, and column name and now it sounds like now i need to pick one table i want to select messages table Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277251 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 SELECT messages.*FROM business_info,messages WHERE business_info.BusinessName=messages.BusinessName try it see if theres any changes Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277258 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277282 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 help please Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277287 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277307 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 ok that is displaying this now Fatal error: Call to undefined function: mysql_fetc_assoc() Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277476 Share on other sites More sharing options...
franknu Posted June 19, 2007 Author Share Posted June 19, 2007 works good now Quote Link to comment https://forums.phpfreaks.com/topic/56122-sql-syntax-error/#findComment-277478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.