Źródło:
Komentarze (0)
| | źródło pochodzi od: sympozjon Opis: Klasa służąca do szukania zadananego wyrażenia w bazie danych. Język: php |
<!--very good data entry page,with confirmation page!//-->
<html>
<head>
<title>data entry page</title>
</head>
<body bgcolor=
"CCCCCC">
<?php
include(
"header.inc");
//header include for data entry page. [not nessesacery you can delete this line #10]
$db =
mysql_connect(
"localhost", "Administrator");
// might have to change user name and host name.
mysql_select_db(
"test",
$db);
// data base name
//i have used my test data vase here.
//you will have to create a table called employees in your test DB in mysql.
//with the following mysql query:
//mysql>use test;
//database changed
//mysql>create table employees( id tinyint(4) default '0' not null auto_increment,
// ->first varchar (255),
// ->last varchar(255),
// ->address varchar(255),
// ->position mediumtext,
// ->primary key (id),
// ->unique id (id));
//
//then go back and view this page and start your data base,
//you will need to create a new php page to veiw the info in your site!
//to upload images from this form simply type in where you will find the image on you server eg:<img src="C:/images/image.gif">
//and this is alot faster that uploading a image to the data base
if (
$submit) {
// here if no ID then adding else we're editing
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')";
}
// run SQL against the DB
$result =
mysql_query(
$sql);
echo "<img src=button1.gif><br><p>Record updated/edited!</p><a href=$PHP_SELF>[ Refresh ]</a>";
}
elseif (
$delete) {
// delete a record
$sql =
"DELETE FROM employees WHERE id=$id";
$result =
mysql_query(
$sql);
echo "<img src=button1.gif><br><p>$sql Record deleted!</p><a href=$PHP_SELF>[ Refresh ]</a>"; }
else {
// this part happens if we don't press submit
if (!
$id) {
// print the list if there is not editing
$result =
mysql_query(
"SELECT * FROM employees",
$db);
while (
$myrow =
mysql_fetch_array(
$result)) {
printf(
"<li><a href="%s?id=%s">%s </a>n", $PHP_SELF, $myrow["id"], $myrow["first"]);
printf(
" <a href="%s?id=%s&delete=yes"><b>[Delete]</b></a><br><br>", $PHP_SELF, $myrow["id"]);
}
}
?>
<P>
<a href=
"<?php echo $PHP_SELF?>">[Add a record]</a>
<P>
<
form method=
"post" action="<?php echo $PHP_SELF?>">
<?php
if (
$id) {
// editing so select a record
$sql =
"SELECT * FROM employees WHERE id=$id";
$result =
mysql_query(
$sql);
$myrow =
mysql_fetch_array(
$result);
$id =
$myrow[
"id"];
$first =
$myrow[
"first"];
$last =
$myrow[
"last"];
$address =
$myrow[
"address"];
$position =
$myrow[
"position"];
// print the id for editing
?>
<input type=hidden name=
"id" value="<?php echo $id ?>">
<?php
}
?>
<table border=
"1" cellspacing="1" cellpadding="7"><tr><td>
Page title!</td><td><input type=
"Text" name="first" value="<?php echo $first ?>"><br>
</td></tr>
<tr><td>
Header or Images.</td><td><input type=
"Text" name="last" value="<?php echo $last ?>"><br>
</td></tr>
<tr><td>
Info.</td><td><input type=
"Text" name="address" value="<?php echo $address ?>"><br>
</td></tr>
<tr><td valign=
"top">
HTML content!</td><td>
<textarea type=
"input" name="position" value="" rows="20" cols="70"><?php
echo $position ?></textarea>
</td></tr>
<tr><td valign=
"top">
<input type=
"Submit" name="submit" value="Enter information"></td><td valign="top">
<input type=
"reset" name="reset" value="clear fields"><br>
</
form>
</td></tr>
</table>
<?php
}
?>
< /body>
</html>
powrótTagi do źródła:
Przeszukiwanie bazy danych, mysql, sql, php
Nikt jeszcze nie skomentował tego źródła.