Basic Insert/Edit PHP Form Example

A techie post today; no comedy or existential woe on this day..

Here is a very basic example of a PHP/HMTL form. The same form is used to insert and edit data, and it submits to itself. This example does not write any data to a database though.

You can view the form and try it here.

Told you it was basic! Once you understand the code though – the principles can be extended to insert/edit records in a database, and build CMS etcetera.

Here’s the code:

<?php

$name = $_POST[‘name’];

if ($action == “edit”) {

echo “Thank you $name. You can makes changes below if necessary.”;

}

?>

<html>

<form method=”post” action=”form-test.php” >

Name: <input type=”text” name=”name” value=”<?php echo $name; ?>” />

<input type=”hidden” name=”action” value=”edit” />

<input type=”submit” name=”submit” value=”Enter” />

</form>

</html>

Categories:

Web

Disclaimer:

This is a personal website and the views expressed here are my own (or stolen from other people down the pub). Facts may not be accurate, or could be poorly paraphrased gags borrowed from proper writers - or simply, outright lies.
#jokingnotjoking