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
https://forums.phpfreaks.com/topic/287891-syntax-error/
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;

Link to comment
https://forums.phpfreaks.com/topic/287891-syntax-error/#findComment-1476700
Share on other sites

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.