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
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>';

 

Link to comment
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>';

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.