40esp Posted June 9, 2008 Share Posted June 9, 2008 Im getting the: Parse error: syntax error, unexpected T_IF in /var/www/jaikobcreate/sw/dev/admin/edit_signup.php on line 155 Error. Line 155 is: <?php $check_if = if(strstr($is_subscribed, "[$key]")) { "checked=\"checked\""; } ?> Here is the whole chunk of code: <?php $is_subscribed = $row_email_record['practice_groups']; $check_if = if(strstr($is_subscribed, "[$key]")) { "checked=\"checked\""; } foreach($newsletter as $key=>$title) { echo "<input type=\"checkbox\" name=\"select\" id=\"select\" value=\"$key\"".$check_if."/>"; } ?> What did I miss? Link to comment https://forums.phpfreaks.com/topic/109481-solved-parse-error/ Share on other sites More sharing options...
kenrbnsn Posted June 9, 2008 Share Posted June 9, 2008 You can't assign a variable the output of an "if" block. You probably want to have something like this <?php $check_if = (strstr($is_subscribed, "[$key]"))?'checked="checked"':''; ?> Ken Link to comment https://forums.phpfreaks.com/topic/109481-solved-parse-error/#findComment-561607 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 Thanks =] Link to comment https://forums.phpfreaks.com/topic/109481-solved-parse-error/#findComment-561610 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 The problem now, it isn't echoing my html right. <?php echo "<input type=\"checkbox\" name=\"select\" id=\"select\" value=\"$key\"".if(strstr($is_subscribed, "[$key]")) {echo "checked=\"checked\"";}."/>"; ?> it just echoes checked=checked instead of a checkbox... Link to comment https://forums.phpfreaks.com/topic/109481-solved-parse-error/#findComment-561615 Share on other sites More sharing options...
kenrbnsn Posted June 9, 2008 Share Posted June 9, 2008 Why do you have the "if" statement embedded in the echo? You can't do that. Just use the previously defined variable. Ken Link to comment https://forums.phpfreaks.com/topic/109481-solved-parse-error/#findComment-561619 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 I got it, Thank you. =] Link to comment https://forums.phpfreaks.com/topic/109481-solved-parse-error/#findComment-561622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.