Jump to content

Unexpected Variable - Radio Buttons


Recommended Posts

I've tried this every which way that I can think of and I keep getting an error for unexpected variable. I know it has to do with the single quotes around 'Yes' and 'No' but I can't figure out how else to make this work, can anyone help me with the code. Thanks!

 

It's suppose to show Yes or No based on what's in my table (contacts) for the column subscribesearches.

 

<?php

function subscribe ($conn) {

$ID = $_GET['ID'];

    $stmt = $conn->prepare("SELECT ID,subscribesearches,subscribedrips FROM contacts WHERE ID = '$ID'");
	$stmt->execute();
	$stmt->bind_result($ID,$subscribesearches,$subscribedrips);
	$stmt->fetch();  

	echo'
	<td>
	<input type="radio" name="subscribesearches" value="Yes" $subscribesearches == 'Yes' ?  "checked" : "" ><span class="r-input">  Yes</span>
	<input type="radio" name="subscribesearches" value="No" $subscribesearches == 'No' ? "checked" : "" ><span class="r-input">  No</span>
	</td>';

$stmt->close();

}
?>

Link to comment
https://forums.phpfreaks.com/topic/265521-unexpected-variable-radio-buttons/
Share on other sites

You have to break out of your string to do your condition, and use concatenation to join them.

 

	echo'
	<td>
	<input type="radio" name="subscribesearches" value="Yes" '.($subscribesearches == 'Yes' ?  "checked" : "").' ><span class="r-input">  Yes</span>
	<input type="radio" name="subscribesearches" value="No" '.($subscribesearches == 'No' ? "checked" : "").' ><span class="r-input">  No</span>
	</td>';

 

You have to break out of your string to do your condition, and use concatenation to join them.

 

	echo'
	<td>
	<input type="radio" name="subscribesearches" value="Yes" '.($subscribesearches == 'Yes' ?  "checked" : "").' ><span class="r-input">  Yes</span>
	<input type="radio" name="subscribesearches" value="No" '.($subscribesearches == 'No' ? "checked" : "").' ><span class="r-input">  No</span>
	</td>';

 

Awesome, I tried something close to that, but obviously not close enough! Thanks for explaining!

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.