We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


How to put my variable in my if condition in my php function??

Medium Priority
Last Modified: 2012-05-11
Hi, I am trying to put a variable in a $_GET for my conditional if statement

function bracelets() {
	global $conn, $metals;
	$query = "SELECT * FROM bracelets";
	$metal = $metals['name'];
	if(!isset($_GET['{$metal}']) {  // This is line 98
		$query .= " WHERE featured = 1";
	$result = mysql_query($query, $conn);

	$output = "";
	// These loops output the subject names with their corresponding pages underneath them
	while ($bracelets = mysql_fetch_array($result)) {
		//for ($i = 0; $i < 3; $i++) {
		//echo "<img src=\"images/" . $pictures[$i] . "\" />";
		$output .= "<a href=\"bracelets.php?bracelet=" . urlencode($bracelets["id"]) . "\">";
		$output .= "<img src=\"bracelets/" . $bracelets["filename"] . "\" />";
	return $output;

Open in new window

Its giving me this error:

Parse error: syntax error, unexpected '{' in /hermes/web09c/b2950/moo.auroriellacom/includes/library.php on line 98

But how can I get rid of the { when its needed for the if statement?? I took the {$metal} out and I still got the same error message.  Any clues??
Watch Question

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Juan OcasioContinuous Process Improvement Lead

Make sure your brackets are paired properly.  It may be due a bracket prior to this line or even a missing ;


Yep, that worked! Didn't know I could put variables straight up in there like that! Thanks

I just posted another php question about link if you want to take a try at it!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.