Введение в СУБД MySQL


Example.12.4


<?php

$db = mysql_connect("localhost", "root");

mysql_select_db("mydb",$db);

if ($id) {

if ($submit) {

$sql = "UPDATE employees SET first='$first',last='$last',

address='$address',position='$position' WHERE id=$id";

$result = mysql_query($sql);

echo "Thank you! Information updated.\n";

} else {

// query the DB

$sql = "SELECT * FROM employees WHERE id=$id";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);

?>

First name:

Last name:

Address:

Position:

<?php

}

} else {

// display list of employees

$result = mysql_query("SELECT * FROM employees",$db);

while ($myrow = mysql_fetch_array($result)) {

printf("%s %s
\n",

$PHP_SELF, $myrow["id"], $myrow["first"],

$myrow["last"]);

}

}

?>




Начало  Назад  Вперед