mysql - while loop with form with checkbox php not updating based on database details -


i have while loop display information correctly, want checkbox allowing me mark each member of loop completed in database, don't know start , appreciate help.

below how far am, generating loop correctly , displaying checkbox not being set 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 appreciated

you cannot write raw php code in string , hope it's executed. inline cannot use if, have use 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>'; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -