Jump to content

[SOLVED] error in your SQL syntax check server version


travelkind

Recommended Posts

I was trying to run a simple script and have received the following 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 '.duns_num = custmast.duns_num' at line 1

 

My server is hosted so I went and checked the version and here is what it says:  Server version: 5.0.67.d7-ourdelta-log

 

Here is my simple code:

 

<?php

 

$dbhost = "xxxxx";

$dbuser = "xxxxx";

$dbpassword = "xxxxx";

 

$dbdatabase = "ccfee";

 

$db = mysql_connect($dbhost, $dbuser, $dbpassword);

mysql_select_db($dbdatabase, $db);

 

// Make a MySQL Connection

// Construct our join query

$query = "SELECT sunocoimport.duns_num, custmast.fee_percent".

"FROM sunocoimport, custmast".

        "WHERE sunocoimport.duns_num = custmast.duns_num";

 

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

 

// Print out the contents of each row into a table

while($row = mysql_fetch_array($result)){

          echo $row['Duns_num']."-".$row['Fee_percent'];

          echo "<br />";

}

?>

 

Does anyone have any clue? Thanks, Dave

Is there any reason you're concatenating strings with other strings?  The problem could be because you query looks like this:

SELECT sunocoimport.duns_num, custmast.fee_percentFROM sunocoimport, custmastWHERE sunocoimport.duns_num = custmast.duns_num

 

try:

$query = "SELECT sunocoimport.duns_num, custmast.fee_percent FROM sunocoimport, custmast WHERE sunocoimport.duns_num = custmast.duns_num";

Well that solves your SQL syntax problem. The other issue is because of this line:

echo $row['Duns_num']."-".$row['Fee_percent'];

Apparently in all the records you fetched the rows (if they even exist) Duns_num and Fee_percent are empty.

There's no need for that. Just make sure that your rows are named exactly 'Duns_num' and 'Fee_percent'.

 

Edit: Just realized in your query it's lower-case, is it all lower-case in the database? If so use this line:

echo $row['duns_num']."-".$row['fee_percent'];

If it's not all lower-case in your database then just change your query.

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.