php数据库的增删改查 php与javascript之间的交互(2)

javascript控制html节点的详细,可以参照我之前写的《【JavaScript】网页节点的增删改查》一文(点击打开链接

(2)dbinsert.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>dbinsert.php</title> </head> <body> <?php //首先从dbselect.php的表单中接受操作的数据 //dbselect.php故意用到get方法,只是想说明php中对get与post的处理同样可以通过$_REQUEST["变量名"]来实现 $username=$_REQUEST["username"]; $password=$_REQUEST["password"]; //操作数据库的指定动作同dbselect.php。 $con=mysql_connect("localhost","root","root"); if(!$con){ die("连接失败!"); } mysql_select_db("test",$con); //控制数据库比dbselect.php更加简单,因为不用对数据库的查询结果进行处理 //只是要注意,这里连接字符串是用到.的,而不是jsp的+,asp的&,请注意! mysql_query("insert into user(username,password) values ('".$username."','".$password."');"); mysql_close($con); ?> <script> alert("添加成功"); window.location.href="dbselect.php" ; </script> </body> </html>

(3)dbupdate.php
与dbinsert.php逻辑是一模一样的,只是mysql_query那个的查询语句,从insert into语句变成了update语句而已

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <?php $userid=$_REQUEST["userid"]; $rowname=$_REQUEST["rowname"]; $rowtext=$_REQUEST["rowtext"]; $con=mysql_connect("localhost","root","root"); if(!$con){ die("连接失败!"); } mysql_select_db("test",$con); mysql_query("update user set ".$rowname."='".$rowtext."' where;"); mysql_close($con); ?> <script> alert("修改成功"); window.location.href="dbselect.php" ; </script> </body> </html>

以上,就是整个制作过程。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a11676d4308538df9533baf679a16277.html