|
$db = MySQL tutorial _connect ("localhost", "phpdb", "phpdb");
mysql_select_db ("Test", $db);
If the submit button is submitted
if ($submit) {
If there is no ID, the record is incremented, otherwise the record is modified
if ($id) {
$sql = "Update employees set first= ' $first ', last= ' $last ', address= ' $address ', position= ' $position ' where id= $id";
}
else {
$sql = "INSERT INTO employees (first,last,address,position) VALUES (' $first ', ' $last ', ' $address ', ' $position ')";
}
To issue SQL commands to a database tutorial
$result = mysql_query ($sql);
echo "Record modification successful! <> ";
echo "<a href= ' $php _self ' > Return </a>";
}
ElseIf ($delete) {
Delete a record
$sql = "Delete from employees where id= $id";
$result = mysql_query ($sql);
echo "Record deletion succeeded!" <> ";
echo "<a href= ' $php _self ' > Return </a>";
}
else {
If the submit button has not been pressed, execute the following part of the program
if (! $id) {
If the status is not modified, the list of employees is displayed
$result = mysql_query ("SELECT * FROM Employees", $DB);
while ($myrow = Mysql_fetch_array ($result)) {
printf ("<a href="%s?id=%s ">%s%s</a>",
$php _self, $myrow ["id"], $myrow ["a"], $myrow ["last"]);
printf ("<a href="%s?id=%s&delete=yes "> (delete) </a><br>", $php _self, $myrow ["id"]);
}
}
?>
<a href= "<?php echo $php _self?>" > Return </a>
<form method= "POST" action= "<?php echo $php _self?>" >
<?php
if ($id) {
Is in edit modification state, select a record
$sql = "SELECT * FROM Employees where id= $id";
$result = mysql_query ($sql);
$myrow = Mysql_fetch_array ($result);
$id = $myrow ["id"];
$first = $myrow ["a"];
$last = $myrow ["Last"];
$address = $myrow ["Address"];
$position = $myrow ["position"];
Display IDs for users to edit and modify
?>
<input type=hidden name= "id" value= "<?php echo $id?>" >
<?php
}
?>
Name: <input type= "text" name= "one" value= "<?php echo $first?>" >
Surname: <input type= "text" Name= "last" value= "<?php echo $last?>" >
<br>
Address: <input type= "text" name= "adress" value= "<?php echo $address?>" >
Position: <input type= "text" name= "position" value= "<?php echo $position?>" >
<br>
<input type= "Submit" name= "submit" value= "Input Info" >
</form>
<?php
}
?>
</body>
|