表单的增删改查示例

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

代码

$link = mysqli_connect("localhost","root","")or die( mysql_error());

$db_selected = mysqli_select_db($link,"lx_study");

mysqli_query($link, "set names gb2312");//设置中文字符

$cont1 = isset($_POST['cont1'])?$_POST['cont1']:"";

$cont2 = isset($_POST['cont2'])?$_POST['cont2']:"";//NULL

$cont3 =isset($_POST['cont3'])?$_POST['cont3']:"";

$cont4 = isset($_POST['cont4'])?$_POST['cont4']:"";

$cont5 =isset($_POST['cont5'])?$_POST['cont5']:"";

$submit =isset($_POST['submit'])?$_POST['submit']:"";

if($cont1 != '' && $cont2 != '' && $cont3!='' && $cont4!='' && $cont5!='')

{

if($submit == '新增')//提交进行插入工作

{

$re=mysqli_query ($link,"INSERT INTO biao (Cont1, Cont2, Cont3,Cont4,Cont5)VALUES('$_POST[cont1]','$_POST[cont2]','$_POST[cont3]','$_POST[cont4]','$ _POST[cont5]')");

//echo "INSERT INTO biao (Cont1, Cont2, Cont3,Cont4,Cont5) VALUES('$_POST[cont1]','$_POST[cont2]','$_POST[cont3]','$_POST[cont4]','$_POST[cont5]')";

if($re)

{

echo "";

}

else

{

echo "";

}

}

if($submit == '修改')

{

$cont1 = isset($_POST['cont1'])?$_POST['cont1']:"";

$cont2 = isset($_POST['cont2'])?$_POST['cont2']:"";

$cont3 =isset($_POST['cont3'])?$_POST['cont3']:"";

$cont4 = isset($_POST['cont4'])?$_POST['cont4']:"";

$cont5 =isset($_POST['cont5'])?$_POST['cont5']:"";

$submit =isset($_POST['submit'])?$_POST['submit']:"";

$id = isset($_POST['id'])?$_POST['id']:"";

$sql=mysqli_query($link,"UPDATEbiao SET id='$id',cont1='$cont1',cont2='$cont2',cont3='$cont3',cont4='$cont4',cont5='$cont5' where id=$id");

//echo "UPDATE biao SET id='$id',cont1='$cont1',cont2='$cont2',cont3='$cont3',cont4='$cont4',cont5='$cont5' where id=$id";

if($sql)

{

echo "";

}

else

{

echo "";

}

}

}

相关文档
最新文档