this is my first code in php. i am trying this off a tutorial i saw--

i am getting 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 'LEFT JOIN products.products_id=products_description.products_id' at line 8

<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());

// Get all the data from the "product" table
$result = mysql_query("SELECT * FROM products.products_id AS id,
products_description.products_name AS name,
products.products_quantity AS quantity,
products.products_weight AS weight,
products.products_price AS price,


LEFT JOIN products.products_id=products_description.products_id

") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Age</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['id'];
	echo "</td><td>"; 
	echo $row['name'];
	echo "</td></tr>";
	echo $row['quantity'];
	echo "</td></tr>";
	echo $row['weight'];
	echo "</td></tr>";
	echo $row['price'];
	echo "</td></tr>";
} 

echo "</table>";
?>

thanks,

craig

Recommended Answers

All 2 Replies

remove ,

products.products_price AS price,

The query sentense shoud be like

$result = mysql_query("SELECT products.products_id AS id,
products_description.products_name AS name,
products.products_quantity AS quantity,
products.products_weight AS weight,
products.products_price AS price  FROM products, products_description 
LEFT JOIN products.products_id=products_description.products_id
 ")

It should be the table name after "FROM", not the column name ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.