PHP database additions and deletions to check the source code (1)

Source: Internet
Author: User
Tags php database printf unique id

//mysql数据库的sql
CREATE TABLE user( id int(5) DEFAULT '0' NOT NULL AUTO_INCREMENT, name varchar(20), city varchar(20), postcode varchar(10),address varchar(100), password varchar(10), level tinyint(2) DEFAULT '0',right tinyint(2),email varchar(40), PRIMARY KEY (id), UNIQUE id (id));
INSERT INTO myuser VALUES (1,'王友','北京','100083','北京市海淀区学院路',111,0,0,'wangyou000@263.net');
INSERT INTO myuser VALUES (2,'金风','武汉','430071','武汉市武昌区水果湖',111,0,0,'jinfeng000@263.net');
INSERT INTO myuser VALUES (3,'常丽','襄樊','441021','襄樊市襄城区南街',111,0,0,'changli000@263.net');

1. Search All

<title> Search All </title>
<body>
&LT;H2 align=center>
The following are all the contents of the user database:
?
$db = mysql_connect ("localhost", "root");
mysql_select_db ("MySite", $db);
$result = mysql_query ("SELECT * from user", $db);
echo "<table border=1>\n";
echo "<tr><td>id</td><td> name </td>";
echo "<td> City </td><td> postcode </td>";
echo "<td> address </td><td> grade </td>";
echo "<td> permissions </td><td> email address </td>";
echo "</tr>\n";
while ($myrow = Mysql_fetch_row ($result))
{
printf ("<tr><td>%s</td><td>%s</td>", $myrow [0], $myrow [1]);
printf ("<td>%s</td><td>%s</td>", $myrow [2], $myrow [3]);
printf ("<td>%s</td><td>%s</td>", $myrow [4], $myrow [6]);
printf ("<td>%s</td><td>%s</td></tr>\n", $myrow [7], $myrow [8]);
}
echo "</table>\n";
?>
</body>

2. According to the ID query

<body>
<title>
Query by ID
</title>
?
$db = mysql_connect ("localhost", "root");
mysql_select_db ("MySite", $db);
if ($id) {
$result = mysql_query ("SELECT * from user WHERE id= $id", $db);
$myrow = Mysql_fetch_array ($result);
printf ("

printf ("1.ID number%sn<br>", $myrow ["id"]);
printf ("2. Name:%sn<br>", $myrow ["name"]);
printf ("3. Cities:%sn<br>", $myrow ["City"]);
printf ("4 Zip:%sn<br>", $myrow ["postcode"]);
printf ("5. Address:%sn<br>", $myrow ["addresses"]);
printf ("6. Rank:%sn<br>", $myrow ["level"]);
printf ("7. Email address:%sn<br>", $myrow ["email"]);
printf ("<a href="%s "> Continue query </a>", $PATH _info);
}
Else
{
$result = mysql_query ("SELECT * from user", $db);
if ($myrow = mysql_fetch_array ($result))
{
printf ("

do {
printf ("%s<a href="%s?id=%s ">%s </a><br>\n",
$myrow ["id"], $PATH _info, $myrow ["id"], $myrow ["name"]);
}
while ($myrow = Mysql_fetch_array ($result));
}
Else
{
echo "Sorry, no data!" ";
}
}
?>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.