Jump to content

Syntax error?


Simpson

Recommended Posts

Hey,

 

I wrote this code, to make a dynamic table, but I keep getting Syntax error, and I can't see where that error is, plz help.

mysql_connect ("localhost", "USERNAME", "PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error()); 

// Select the database
mysql_select_db ("DATABASE") 
or die ("Could not select database");

// Store Settings
$gable_max_colo = "9";
$box_max_fresh = "2";
$box_max_frozen = "2";

// Getting data
$dep = 'Colonial';
$displayT = 'Gable';

$res = mysql_query("SELECT * FROM Marketing WHERE Year='".$_POST['year']."' and Week='".$_POST['week']."'");

while ($row = mysql_fetch_array($res)){
	$dep = $row['Department'];
	$displayT = $row['DisplayType'];
		if ($dep == 'Colonial'){
			if ($displayT == 'Gable'){
				$number = '1';
				while ($number > $gable_max_colo){
					$result = mysql_query("SELECT * FROM Marketing WHERE Year'".$_POST['year']."' and Number='".$number."' and DisplayType='".$displayT."' and Department='".$dep."' and Week='".$_POST['week']."'");
					
					$html_start = '<h2>Endegavl'.$number.'</h2>
					<table border="1" cellspacing="4" cellpadding="4">
						<tr>
							<th>Brand</th>
							<th align="right">Product</th>
							<th align="left">Type</th>
							<th>Price</th>
						</tr>';
					
					while ($row = mysql_fetch_array($result)){
					$Product = $row['Product'];
					$Brand = $row['Brand'];
					$Price = $row['Price'];
					$ProductT = $row['ProductType'];
					$Count = $row['Count'];
					$Goods = $row['Goodsnr'];
					$html_inside .= '
						<tr>
							<td>'.$Brand.'</td>
							<td>'.$Product.'</td>
							<td>'.$Type.'</td>
							<td>'.$Price.'</td>
						</tr>';
					}
					$html_end = '</table>';
					$number = $number + 1;
			}
		}
}

echo $html_start;
echo $html_inside;
echo $html_end;
Link to comment
Share on other sites

I do not like the mysql_connect and mysql_select_db statements. If you found that in a book, please review the language being used. Let us know how this statemnent is supposed to work.

 

PHP should report the line number on which the error occured. May I ask what environment you are programming in where PHP does not indicate the line number where an error occured?

 

mysql_connect should return with a connection handle, true, or false. We need to test for that and deal with the failure:

if (($db = mysql_connect ("localhost", "USERNAME", "PASSWORD")) === false) { die ('I cannot connect to the database because: ' . mysql_error()); }

 

I also see:

while ($number > $gable_max_colo){

does not have a closing brace after:

$number = $number + 1;

Edited by bsmither
Link to comment
Share on other sites

Fact is at this point he or she shouldn't be using the mysql_ functions at all as they're deprecated, instead opting for PDO or mysqli.

 

Also, not sure exactly what the goal is, but nested queries are never a good sign.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.