iseriouslyneedhelp Posted July 11, 2012 Share Posted July 11, 2012 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/265521-unexpected-variable-radio-buttons/ Share on other sites More sharing options...
kicken Posted July 11, 2012 Share Posted July 11, 2012 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/265521-unexpected-variable-radio-buttons/#findComment-1360799 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/265521-unexpected-variable-radio-buttons/#findComment-1360802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.