Database Add, modify, delete base operation code (1/4)

Source: Internet
Author: User
Tags add time

Require_once (' common.php ');
$action = $_get[' action '];
?>

The code is as follows Copy Code

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Talent List </title>
<link href= "style.css tutorial" type= "Text/css" rel= "stylesheet"/>
<body>
<div id= "Wrap" >
<div id= "Main" >
<?php
if ($action = = ' Add ') {
?>
<form action= "? Action=save" method= "Post" Name= "Form1" >
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 0 "class=" POST ">
<tr>
&LT;TD colspan= "2" > Add people </td></tr>
&LT;TR&GT;&LT;TD width= > Login account </td>
&LT;TD width= "><input" name= "Login" type= "text" id= "Login"/></td>
</tr>
<tr>
<td> Login Password </td>
<td><input name= "PWS" type= "text" id= "PWS"/></td>
</tr>
<tr>
<td> issues </td>
<td><input name= "question" type= "text" id= "question"/></td>
</tr>
<tr>
<td> Answers </td>
<td><input name= "Answer" type= "text" id= "Answer"/></td>
</tr>
<tr>
&LT;TD colspan= "2" ><input name= "button" type= "Submit" id= "button" value= "Add"/></td>
</tr>

</table>
</form>
<?php
}
ElseIf ($action = = ' Save ') {
$login = isset ($_post[' login ')? $_post[' login ']: ';
$PWS = isset ($_post[' PWS '))? $_post[' PWS ']: ';
$question = isset ($_post[' question '))? $_post[' question ']: ';
$answer = isset ($_post[' answer '))? $_post[' answer ']: ';
$sql = "INSERT into person (login,pws,question,answer)
VALUES (' $login ', ' $pws ', ' $question ', ' $answer ');
$db->query ($sql);
Forward (' Publish success ', ' href ', ' personlist.php ');
}

ElseIf ($action = = ' del ') {
$person _id=$_get[' person_id '];
$page =$_get[' page '];
$sql = "Delete from the person where person_id= ' $person _id '";
$db->query ($sql);
Forward (' delete success ', ' href ', ' personlist.php?page= '. $page);
}
ElseIf ($action = = ' Editsave ') {
$person _id = isset ($_post[' person_id '))? $_post[' person_id ']: ';
$page = isset ($_post[' page ')? $_post[' page ']: ';
$login = isset ($_post[' login ')? $_post[' login ']: ';
$PWS = isset ($_post[' PWS '))? $_post[' PWS ']: ';
$question = isset ($_post[' question '))? $_post[' question ']: ';
$answer = isset ($_post[' answer '))? $_post[' answer ']: ';
$sql = "Update person set login= ' $login ', pws= ' $PWS ', question= ' $question ', answer= ' $answer ' where person_id= ' $person _ Id ' ";
$db->query ($sql);
Forward (' Modify success ', ' href ', ' personlist.php?page= '. $page);
}
ElseIf ($action = = ' edit ') {
$person _id=$_get[' person_id '];
$page =$_get[' page '];
$sql = "SELECT * from person where person_id= ' $person _id '";
$query = $db->query ($sql);
$row = $db->fetch_array ($query);
$login = $row [' Login '];
$PWS = $row [' PWS '];
$question = $row [' Question '];
$answer = $row [' answer '];
?>
<form action= "? Action=editsave" method= "Post" Name= "Form1" >
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 0 "class=" POST ">
<tr>
<input name= "page" type= "hidden" value= "<?php echo $page?>"/>
<input name= "person_id" type= "hidden" value= "<?php echo $person _id?>"/>
&LT;TD colspan= "2" > Modify Personnel </td></tr>
&LT;TR&GT;&LT;TD width= > Login account </td>
&LT;TD width= "><input" name= "Login" type= "text" id= "login" value= "<?php echo $login?>"/></td>
</tr>
<tr>
<td> Login Password </td>
<td><input name= "PWS" type= "text" id= "PWS" value= "<?php echo $pws?>"/></td>
</tr>
<tr>
<td> issues </td>
<td><input name= "question" type= "text" id= "question" value= "<?php echo $question?>"/></td>
</tr>
<tr>
<td> Answers </td>
<td><input name= "Answer" type= "text" id= "answer" value= "<?php echo $answer?>"/></td>
</tr>
<tr>
&LT;TD colspan= "2" ><input name= "button" type= "Submit" id= "button" value= "Modify"/></td>
</tr>

</table>
</form>
<?php
}
else{
$page = isset ($_get[' page ')? Intval ($_get[' page '): 1;
$num = 5;
$sql = "SELECT * from person";
$query = $db->query ($sql);
$totalnum = $db->num_rows ($query)//Total Records
$pagenum = Ceil ($totalnum/$num); Total pages
$offset = ($page-1) * $NUM;
$sql = $sql. "Limit $offset, $num";
$query = $db->query ($sql)//Get a record
?>
<table width= "639" border= "0" cellspacing= "0" cellpadding= "0" class= "POST" >
<tr>
&LT;TD colspan= "6" > Total records: <?php echo $totalnum;? > ———— <a href= "Personlist.php?action=add" > Add people </a></td></tr>
&LT;TR&GT;&LT;TD width= "126" > Login account </td>
&LT;TD width= > Login Password </td>
&LT;TD width= > Problem </td>
&LT;TD width= > Answer </td>
&LT;TD width= "138" > Add time </td>
&LT;TD width= > Operation </td>
</tr>
<?php
while ($row = $db->fetch_array ($query)) {
?>
<tr>
<td><?php echo $row [' login '];? ></td>
<td><?php echo $row [' PWS '];? ></td>
<td><?php echo $row [' question '];? ></td>
<td><?php echo $row [' answer '];? ></td>
<td><?php echo $row [' addtime '];? ></td>
<td><a href= "? action=del&person_id=<?php echo $row [' person_id ']? >&page=<?php echo $page? > "> Delete </a>/
<a href= "? action=edit&person_id=<?php echo $row [' person_id ']? >&page=<?php echo $page?>" > Modify </a></td>
</tr>
<?php
}
?>
</table>
</div>
<div id= "Pages_btns" >
<div class= "pages" ><?php showpage ($page, $num, $pagenum, $totalnum)?></div>
</div>
<?php
}
?>
</div>
</body>

home 1 2 3 4 last page

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.