PHP插入数据库代码,编辑,删除
作者:互联网
插入代码
view plaincopy <?
$action=$_GET['action'];
switch($action){
//添加记录
case"add";
$mail = trim(htmlspecialchars($_POST["mail"]));
$username = trim(htmlspecialchars($_POST["username"]));
$tel = trim(htmlspecialchars($_POST["tel"]));
$fax = 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>";//*/
}?>
编辑代码
view plaincopy
<?
$action=$_GET['action'];
switch($action){
//添加记录
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>
删除代码
[xhtml] view plaincopy <a href="?action=del&id=<? echo $rs['id'];?>" οnclick="return confirm('确定删除?')">删除</a> <?
$action=$_GET['action'];
switch($action){
//删除记录
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;
}
?>
转载于:https://www.cnblogs.com/bwzhangtao/p/4233346.html
标签:trim,数据库,htmlspecialchars,插入,sql,action,POST,PHP,id 来源: https://blog.csdn.net/weixin_30596023/article/details/99592045