I keep getting a syntax error in this code and I need a new set of eyes to show me what I am doing wrong. It is coming back and saying that I have an unexpected } on line 36.

<?php

require_once("config.php");

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}

//Create query
$qry=("SELECT * FROM registrants");
$result=mysql_query($qry);

//Run through the records retrieved with the MySQL query.
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
	//set a to the first week
	$a = 1;
	$output .= '<input name="id'. $row[id] . '" type="hidden" value="' . $row[id] . '" />'; //Setup the hidden input so each row has its own id.
	$output .= 'Name: ' . $row[f_name] . ' ' . $row[l_name]; //Output the first and last name with a space between them.
	$week = explode(",",$row[x]); //Turn row[x] into an array with the explode command, where x is the name of the field
	foreach ($week as $w){ //for every item in the array week do the following
		//Store the information into the variable output
		$output .= 'Week ' . $a .' 
		<select name="week'. $row[id] . '[]">
			<option value="Yes">yes</option>
			<option value="No">No</option>
			<option value="' . $w .'" selected="selected">' . $w .'</option>
		</select>';
	$a += 1}; //Increase the count by 1
}; 

?>

Any help is always appreciated. Also, any recommendations for reading material starting out with PHP and mySQL?

I modified your code. Take a look at the * sign.

* is partner with *, and ** is partner with **, and *** is partner with ***, and so on

The problem is you have { in your foreach, and yet you forgot to put } at the end of the foreach statement.

<?php
 
require_once("config.php");
 
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {//*
	die('Failed to connect to server: ' . mysql_error());
}//*
 
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {//**
	die("Unable to select database");
}//**
 
//Create query
$qry=("SELECT * FROM registrants");
$result=mysql_query($qry);
 
//Run through the records retrieved with the MySQL query.
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){//***
	//set a to the first week
	$a = 1;
	$output .= '<input name="id'. $row[id] . '" type="hidden" value="' . $row[id] . '" />'; //Setup the hidden input so each row has its own id.
	$output .= 'Name: ' . $row[f_name] . ' ' . $row[l_name]; //Output the first and last name with a space between them.
	$week = explode(",",$row[x]); //Turn row[x] into an array with the explode command, where x is the name of the field
	foreach ($week as $w){//**** //for every item in the array week do the following
		//Store the information into the variable output
		$output .= 'Week ' . $a .' 
		<select name="week'. $row[id] . '[]">
			<option value="Yes">yes</option>
			<option value="No">No</option>
			<option value="' . $w .'" selected="selected">' . $w .'</option>
		</select>';
	$a += 1}; //Increase the count by 1
}//**** this the problem
} //***
 
?>
<?php

require_once("config.php");

//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {//*
die('Failed to connect to server: ' . mysql_error());
}//*

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {//**
die("Unable to select database");
}//**

//Create query
$qry=("SELECT * FROM registrants");
$result=mysql_query($qry);

//Run through the records retrieved with the MySQL query.
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){//***
//set a to the first week
$a = 1;
$output .= '<input name="id'. $row[id] . '" type="hidden" value="' . $row[id] . '" />'; //Setup the hidden input so each row has its own id.
$output .= 'Name: ' . $row[f_name] . ' ' . $row[l_name]; //Output the first and last name with a space between them.
$week = explode(",",$row[x]); //Turn row[x] into an array with the explode command, where x is the name of the field
foreach ($week as $w){//**** //for every item in the array week do the following
//Store the information into the variable output
$output .= 'Week ' . $a .' 
<select name="week'. $row[id] . '[]">
<option value="Yes">yes</option>
<option value="No">No</option>
<option value="' . $w .'" selected="selected">' . $w .'</option>
</select>';
$a += 1}; //Increase the count by 1
}//**** this the problem
} //***

?>

Ahh, the bracket is on the inside of the semicolon on line 36 and should be outside, which is why you added that other one. That should work. Thanks for the eyes.

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.