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

Posted on 2011-04-25
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??
Question by:FairyBusiness

Accepted Solution

AnuarJamlus earned 2000 total points
ID: 35463950
Try changing this if(!isset($_GET['{$metal}']) {  // This is line 98

to this

if(!isset($_GET['$metal'])) {  // This is line 98
LVL 15

Expert Comment

by:Juan Ocasio
ID: 35463955
Make sure your brackets are paired properly.  It may be due a bracket prior to this line or even a missing ;

Author Closing Comment

ID: 35463962
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!

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question