I am having a php form, and a lot of markup, so i need to repeat the same form for creating a new page entry and same for editing, so for example what am doing right now is
if($_GET['page'] == 'hello') {
//A whole lot of markup goes here
<form method="post">
<input type="text" name="whatever" />
<input type="submit" name="create_new" />
</form>
} elseif ($_GET['page'] == 'edit_hello') {
//Same form markup is here, only change is the retrieved
//data values are echo'ed out in respective fields
$query = mysqli_fetch_array(mysqli_query(...));
<form method="post">
<input type="text" name="whatever" value="<?php echo $query['column_name']; ?>" />
<input type="submit" name="create_new" />
</form>
}
So any idea how can I use the same code for creating new entry as well as updating the form values
Use a variable and give it a default value of an empty string.
Note that I’ve also added proper escaping for you, so that you can avoid XSS attacks.