Hi everybody,

I'm having trouble with my query on line 19. I'm supposed to search for a name and return the balance and credit limit. I'm not sure why I keep getting a parse error.

Thanks in advance!

<?php
	$find=$_POST['find'];
	$name=trim($_POST['name']);
	
	if (!$name) {
		echo 'You have not entered a name. Please go back and try again.';
		exit;
	}
	
	$db = mysql_connect();
	mysql_select_db("Premiere", $db);
	
	if (!$db) {
		die('Could not connect to the database, error # ' . mysql_error() );
	} else
		echo 'The mysql_connect succeeded'."<br />";

	if ($find == a) {
		$query = "SELECT BALANCE, CREDIT_LIMIT FROM CUSTOMER WHERE ".$find" LIKE '%".$name."%'";
	} if ($find == b){
		$query = "SELECT * FROM ORDER, CUSTOMER WHERE ".$find" LIKE '%".$name."%'" AND CUSTOMER.CUSTOMER_NUM = ORDER.CUSTOMER_NUM;
	} else 
		echo 'Match could not be found';
	
	$result = mysql_query($query, $db);
	$num_results = mysql_num_rows($result);
	
	echo "<p>Number of results found: ".$num_results."</p>";
	
	if ($find == a) {
		for ($i=0; $i < $num_results; $i++) {
			$row = mysql_fetch_assoc($result);
			echo "<p>".($i+1).". Name: ";
			echo $name;
			echo "<br />Balance: ";
			echo $row['BALANCE'];
			echo "<br />Credit Limit: ";
			echo $row['CREDIT_LIMIT'];
			echo "</p>";
			}
	} else
		for ($i=0; $i < $num_results; $i++) {
			$row = mysql_fetch_assoc($results);
			echo "<p>".($i+1).". Name: ";
			echo $name;
			echo "<br />Orders: ";
			echo $row['ORDER'];
			echo "</p>";
			}
mysql_free_result($result);
mysql_close($db);
?>
</body>
</html>

Recommended Answers

All 5 Replies

The query on line 19 and 21 both contain the same error. It should be:

if ($find == a) {
	$query = "SELECT BALANCE, CREDIT_LIMIT FROM CUSTOMER WHERE ".$find." LIKE '%".$name."%'";
}
if ($find == b){
	$query = "SELECT * FROM ORDER, CUSTOMER WHERE ".$find." LIKE '%".$name."%' AND CUSTOMER.CUSTOMER_NUM = ORDER.CUSTOMER_NUM";
} else echo 'Match could not be found';

Hey I don't mean to sound ungrateful but I don't see any change in your code to what I already have in my code Colweb. I'm still receiving a parse error and I suspect it's the syntax of my query. Is my LIKE syntax correct? This is truly boggling my mind. . .

Thanks!

You're missing the period after the $find variable

My bad, thanks for pointing out it for me genevish! I'm going to go ahead and mark this as solved.

Thanks again!

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.