0

I've been trying to create 2 radiobuttons to set tasks to complete or not complete but the value of the radiobuttons is passed to the variable

<?php
echo "<form method='post'>";
echo  'Completed:';
echo "<input type='radio' name='complete' value='1'>";
echo 'Yes';
echo "<input type='radio' name='complete' value='0'>" ;
echo 'No';
echo '</form>';

if (isset($_POST['complete'])){
    $complete_btn= $_POST['complete'];
    echo $complete_btn;
?>
}

What im trying to do is bold the tasks that have been marked as completed but for some reason i cannot get the value from the buttons.

(im a complete beginner btw so sorry if it's a stupid question).

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
R AND B
  • 51
  • 2
  • 9
  • 2
    Is this a simple TYPO where you have the if's closing brace `}` outside the `?>` tag, causing a `no compile senario`? – RiggsFolly Aug 21 '19 at 12:45
  • You need to submit the form first to get the $_POST values – Moses Schwartz Aug 21 '19 at 12:48
  • sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** – RiggsFolly Aug 21 '19 at 12:48
  • If you expect something to be in `$_POST['complete']` you would actually need to submit the form and there is no need to echo every line of html, just put your html outside of `` – empiric Aug 21 '19 at 12:48
  • @empiric isn't the form submitted? () – R AND B Aug 21 '19 at 12:53
  • @RiggsFolly how can i enable sensible code identation? – R AND B Aug 21 '19 at 12:54
  • That would only be the end tag of the form, submitting the form would work via pressing `` – empiric Aug 21 '19 at 12:54
  • There no "button" in this form. this means its not submitted ever. Add to the form. Then you can click that to submit it. After which the page should reload and your php code should execute. Of course this is a basic task and there are plenty of tutorials aimed at beginners to show you how this should be done. – CodingInTheUK Aug 21 '19 at 12:57
  • 1
    John, you get a decent text editor, (free one might be notepad++) and you set the tabs to be 4 spaces and NOT tabs. Then it is just a case of being tidy when you write code – RiggsFolly Aug 21 '19 at 12:57
  • I am not sure you are yet at the IDE stage of programming, however NetBeans is a great free IDE with auto complete which can greatly aid your learning process. – CodingInTheUK Aug 21 '19 at 13:00
  • @empiric Thank you ! its now working but can you please explain why it was not working before using the submit button? – R AND B Aug 21 '19 at 13:01
  • @Chris i'm currently using Atom if thats ok? – R AND B Aug 21 '19 at 13:02
  • I would recommend looking at basic tutorials on how to handle forms with php, but for a basic explanation: a `form` tag itself does nothing, you require user interaction (via clicking a button) to actually submit and thus post data to your server. There are other ways but these will exceed the basics – empiric Aug 21 '19 at 13:07
  • Never used Atom, though if you find it useful then I would say yes. There are a vast range of editing software so you can take your pick. You may find down the road that another software has features you want and there is no harm switching, just remember that you may have to learn a new system to do so. – CodingInTheUK Aug 21 '19 at 15:39

0 Answers0