PHP Insert Database Code, edit, delete

Source: Internet
Author: User

Inserting code

View Plaincopy<?

$action=$_get[' action '];

Switch ($action) {

Add a record

Case "Add";

$mail = Trim (htmlspecialchars ($_post["Mail"]));

$username = Trim (htmlspecialchars ($_post["username"));

$Tel = trim (Htmlspecialchars ($_post["Tel"]));

$传真 = Trim (htmlspecialchars ($_post["Fax"));

$ company= Trim (htmlspecialchars ($_post["Company"));

$address = Trim (Htmlspecialchars ($_post["Address")); $sql="insert into Crm_company (mail,username,tel,fax,company,address,addtime) VALUES (' $mail ', ' $  Username ', ' $tel ', ' $fax ', ' $company ', ' $address ', ' $addtime ');

Echo $sql;

mysql_query ($sql, $conn);

Print "<mce:script type=" Text/javascript "><!--  location.href=' c_companylist.php '; //--></mce:script> ";//*/

}?>

Edit Code

View Plaincopy

<?

$action =$_get[' action '];

Switch ($action) {

Add a record

Case"edit";

$uid = Trim (Htmlspecialchars ($_post["UID"));

$regtime = Trim (Htmlspecialchars ($_post["Regtime"));

$deadline = Trim (Htmlspecialchars ($_post["deadline"));

$item = Trim (Htmlspecialchars ($_post["item2"));

$price = Trim (Htmlspecialchars ($_post["price"));

$product = Trim (Htmlspecialchars ($_post["Product"));

$content = Trim (Htmlspecialchars ($_post["content"));

$sql ="Update crm_info set uid= ' $uid ', regtime= ' $regtime ', deadline= ' $deadline ', item= ' $item ', price= ' $price ',  Product= ' $product ', content= ' $content ' where id= ' $id ' ";

Echo $sql;

mysql_query ($sql, $conn);

Print "<mce:script type=" Text/javascript "><!--

location.href=' c_infolist.php '; //--></mce:script> ";//*/

}?>

<form id="Form1" Name="Form1" method= "post" action="? action=edit&id=<?php echo $rs [' id '];? > "onsubmit=" return Checkadd () ">

</form>

Delete code

[XHTML]View Plaincopy<a href="? action=del&id=<? echo $rs [' id '];? > " onclick=" return confirm (' OK delete? ') ' > Delete </a> <?

$action=$_get[' action '];

Switch ($action) {

Deleting records

Case "Del";

$id=$_get[' id '];

$sql="Delete from Crm_info where id= ' $id '";

mysql_query ($sql, $conn);

Print "<mce:script type=" Text/javascript "><!--  location.href=' c_infolist.php ';   //--></mce:script> ";

Break

}

?>

PHP Insert Database Code, edit, delete

Related Article

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.