0

I have a while loop which is display all information correctly, I want a checkbox allowing me to mark each member of the loop as completed in the database, I don't really know where to start with this and I would appreciate any help.

Below is how far I am, it is generating the loop correctly and displaying the checkbox however it is not being set as completed on loading?

    while ($row = mysql_fetch_array($query)){
        $task_name = $row['task_name'] ;
        $task_description = $row['task_description'];
        $task_completed = $row['completed'];
        $tasks .= '<div id="tasksBody"><form action="" method="post">Completed? <input name="completed" type="checkbox" if ($task_completed == 1){checked="checked"} /><input type="submit" value="Update"><br /><br /><b>'.$task_name.'</b><br /><br />'.$task_description.'<hr><br /></form></div>';
    }
}

Any advice would be greatly appreciated

1 Answer 1

3

You cannot write raw PHP code in a string and hope that it's executed. Inline you also cannot use if, but you have to use the ternary operator.

$tasks .= '<div id="tasksBody">
<form action="" method="post">Completed? <input name="completed" type="checkbox" '.
($task_completed == 1?'checked="checked"':'').
' /><input type="submit" value="Update">
<br /><br />
<b>'.$task_name.'</b><br /><br />'.$task_description.'<hr><br /></form></div>';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.