We must update the database by doing inserts.
Wouldn't it be practical that we use the same form and program for
updates.
The requirement is that the form can display already existing data in the form
entry fields, so that they are easy to modify.
The db handling program is easy to expand se here:
<?php
ini_set("include_path", ".:../globaLib:");
require_once "myConnect.inc.php";
if ($_POST['funktion'] == "insert") {
$sql = "insert into city";
$sql .= " (name, district, countrycode, population)";
$sql .= " values('";
$sql .= $_POST['name'];
$sql .= "','";
$sql .= $_POST['district'];
$sql .= "','";
$sql .= $_POST['countrycode'];
$sql .= "','";
$sql .= $_POST['population'];
$sql .= "')";
mysql_query($sql) or die($sql . "<br />Fejl i insert, check sql-sætning");
} else if ($_POST['funktion'] == "update") {
$sql = "update city set name = '" . $_POST['name'] . "'";
$sql .= ", district = '" . $_POST['district'] . "'";
$sql .= ", countrycode = '" . $_POST['countrycode'] . "'";
$sql .= ", population = " . $_POST['population'];
$sql .= " where id = " . $_POST['id'];
mysql_query($sql) or die($sql . "<br />Fejl i update, check sql-sætning");
} else if ($_POST['funktion'] == "delete") {
$sql = "delete from city where id = " . $_POST['id'];
mysql_query($sql) or die($sql . "<br />Fejl i delete, check sql-sætning");
}
header("Location: " . "dbOpgave110Model.php");
?>