php怎样提交数据库 php提交表单数据到数据库

PHP表单提交不同数据到数据库的不同表的不同字段怎么实现?你可以用 PHP 的 MySQLi 或 PDO 库来实现 。
首先,你需要使用这些库中的函数连接数据库,然后把表单中的字段值插入到相应的数据表中 。
例如,如果你使用 MySQLi,你可以这样写:
$conn = mysqli_connect("hostname", "username", "password", "database_name");
$rwid = $_POST['rwid'];
$rwdj = $_POST['rwdj'];
$rwzb = $_POST['rwzb'];
$sql1 = "INSERT INTO table_a (s) VALUES ('$rwid')";
mysqli_query($conn, $sql1);
$sql2 = "INSERT INTO table_b (d) VALUES ('$rwdj')";
mysqli_query($conn, $sql2);
$sql3 = "INSERT INTO table_c (f) VALUES ('$rwzb')";
mysqli_query($conn, $sql3);
如果你使用 PDO , 你可以这样写:
$conn = new PDO("mysql:host=hostname;dbname=database_name", "username", "password");
$rwid = $_POST['rwid'];
$rwdj = $_POST['rwdj'];
$rwzb = $_POST['rwzb'];
$stmt1 = $conn-prepare("INSERT INTO table_a (s) VALUES (:s)");
$stmt1-bindParam(':s', $rwid);
$stmt1-execute();
$stmt2 = $conn-prepare("INSERT INTO table_b (d) VALUES (:d)");
$stmt2-bindParam(':d', $rwdj);
$stmt2-execute();
$stmt3 = $conn-prepare("INSERT INTO table_c (f) VALUES (:f)");
$stmt3-bindParam(':f', $rwzb);
$stmt3-execute();
希望这个答案对你有帮助 。
如何用php页面提交表单到数据库1:首先要使用PHP的超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data) 2:然后使用INSERT INTO 语句用于向数据库表中插入新记录 。具体示例: (1)首先创建了一个名为 "Persons" 的表,有三个列:"Firstname", "Lastname" 以及 "Age" 。
php中按钮怎么提交数据到数据库中?利用表单提交php怎样提交数据库,范例代码如下:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title无标题文档/title
/head
body
table
form name="" action="ip地址" method="post"(这里是新增php怎样提交数据库的)
tr
td valign="top" height="110"兴趣特长:/td
tdtextarea name="content"rows="6" class="textarea0" style="width:630px" /textarea/td
/tr
tr
td valign="top"自php怎样提交数据库我评价:/td
tdtextarea name="content"rows="6" class="textarea0" style="width:630px" /textarea/td
/tr
tr
td colspan="2" align="center"input type="submit" value="https://www.04ip.com/post/提交" //td
/tr
/form (这里是新增的)
/table
/body
/html
php如何提交表格中某个数据到数据库写个简单的吧
a.php
form method="post" action="b.php"
input type="text" name="test" value=""这是你要提交的数据
input type="submit" value="https://www.04ip.com/post/提交"
/form
点击提交按钮就跳到b页面了
b.php
echo $_POST['test'];
打印a提交过来的数据,如果有数据你就自己写sql语句存入数据库就好了
【php怎样提交数据库 php提交表单数据到数据库】php怎样提交数据库的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php提交表单数据到数据库、php怎样提交数据库的信息别忘了在本站进行查找喔 。

    推荐阅读