Additions and deletions to deal with

Source: Internet
Author: User

Home:

<table width= "100%" border= "1" cellpadding= "0" cellspacing= "0" >
<tr>
<td> Code </td>
<td> name </td>
<td> Sex </td>
<td> ethnic </td>
<td> Birthdays </td>
</tr>

<?php
$db = new Mysqli ("localhost", "root", "" "," mydb ");
!mysqli_connect_error () or Die ("Connection failed! ");
$sql = "SELECT * from Info";
$result = $db->query ($sql);
if ($result)
{
$attr = $result->fetch_all ();
foreach ($attr as $a)
{
$sex = $a [2]? " Male ":" Female ";
$sql 1 = "Select Name from Nation where code= ' {$a [3]} '";
$re 1 = $db->query ($sql 1);
$attr 1 = $re 1->fetch_assoc ();
echo "<tr>
<td>{$a [0]}</td>
<td>{$a [1]}</td>
<td>{$sex}</td>
<td>{$attr 1[' Name ']}</td>
<td>{$a [4]}</td>
<td><a href= ' delete.php?code= $a [0] ' > Delete </a></td>
<td><a href= ' updeat.php?code= $a [0] ' > Modify </a></td>
</tr> ";
}
}
?>

</table>
<div><a href= "add.php" > Add Data </a></div>

Add Data:

<form action= "addchuli.php" method= "POST" >
<div> code: <input type= "text" name= "code"/></div>
<div> Name: <input type= "text" name= "name"/></div>
<div> Gender:
<input type= "Radio" value= "male" name= "sex"/> Male
<input type= "Radio" value= "female" name= "sex"/> Female
</div>
<div> Nationalities:
<select name= "Nation" >
<?php

$db = new Mysqli ("localhost", "root", "" "," mydb ");
$sql = "SELECT * from Nation";
$r = $db->query ($sql);
$attr = $r->fetch_all ();
foreach ($attr as $v)
{
echo "<option value= ' $v [0] ' >{$v [1]}</option>";
}

?>
</select>
</div>
<div> Birthdays: <input type= "text" name= "Birthday"/></div>
<div><input type= "Submit" value= "Add Data"/></div>
</form>
<div><a href= "main.php" > Homepage </a></div>

Increased processing:

<?php
$code = $_post["code"];
$name = $_post["name"];
$sex = $_post["Sex"];
$s = 1;
if ($sex = = "female")
{
$s = 0;
}
$nation = $_post["Nation"];
$birthday = $_post["Birthday"];
$db = new Mysqli ("localhost", "root", "" "," mydb ");
!mysqli_connect_error () or Die ("Connection failed! ");
$c = "INSERT into info values (' {$code} ', ' {$name} ', {$s}, ' {$nation} ', ' {$birthday} ')";
$r = $db->query ($c);
if ($r)
{
Header ("location:add.php");
}
Else
{
echo "Add failed!";
}

Modify:

H1> Modifying Data <?php
$code 1 = $_get["code"];
$db = new Mysqli ("localhost", "root", "" "," mydb ");
!mysqli_connect_error () or Die ("Connection failed! ");
$sql = "SELECT * from info where code= ' {$code 1} '";
$r = $db->query ($sql);
$attr = $r->fetch_row ();
?>
<form action= "updeatchuli.php" method= "POST" >
<div><input type= "hidden" value= "<?php echo $attr [0]?>" name= "code"/></div>
<div> Name: <input type= "text" value= "<?php echo $attr [1]?>" name= "name"/></div>
<div> Gender:
<input type= "Radio" value= "male" name= "Sex" <?php echo $attr [2]? Checked= ' checked ' ":" "?>/> male
<input type= "Radio" value= "female" name= "Sex" <?php echo $attr [2]? ":" Checked= ' checked ' "?>/> female
</div>
<div> Nationalities:
<select name= "Nation" >
<?php


$sql 1 = "SELECT * from Nation";
$r 1 = $db->query ($sql 1);
$attr 1 = $r 1->fetch_all ();
foreach ($attr 1 as $v)
{
if ($v [0]== $attr [3])
{
echo "<option selected= ' selected ' value= ' {$v [0]} ' >{$v [1]}</option> ';
}
Else
{
echo "<option value= ' {$v [0]} ' >{$v [1]}</option>";
}
}

?>
</select>
</div>
<div> Birthdays: <input type= "text" value= "<?php echo $attr [4]?>" name= "Birthday"/></div>
<div><input type= "Submit" value= "Modify Data"/></div>
</form>
<div><a href= "main.php" > Homepage </a></div>

Modification Processing:

<?php
$code = $_post["code"];
$name = $_post["name"];
$sex = $_post["Sex"];
$s = 1;
if ($sex = = "female")
{
$s = 0;
}
$nation = $_post["Nation"];
$birthday = $_post["Birthday"];
$db = new Mysqli ("localhost", "root", "" "," mydb ");
!mysqli_connect_error () or Die ("Connection failed! ");
$c = "Update info set name= ' {$name} ', sex= ' {$s} ', nation= ' {$nation} ', birthday= ' {$birthday} ' where code= ' {$code} '";
$r = $db->query ($c);
if ($r)
{
Header ("location:updeat.php");
}
Else
{
echo "Modification failed!";
}

Delete:

<?php
$code = $_get["code"];
$db = new Mysqli ("localhost", "root", "" "," mydb ");
!mysqli_connect_error () or Die ("Connection failed! ");
$sql = "Delete from info where code = ' {$code} '";
$r = $db->query ($sql);
if ($r)
{
Header ("location:sy.php.php");
}
Else
{
echo "Delete failed! ";
}

Additions and deletions to deal with

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.