写个简单的吧
成都创新互联主营让胡路网站建设的网络公司,主营网站建设方案,成都App定制开发,让胡路h5小程序开发搭建,让胡路网站营销推广欢迎让胡路等地区企业咨询
a.php
form method="post" action="b.php"
input type="text" name="test" value=""这是你要提交的数据
input type="submit" value="提交"
/form
点击提交按钮就跳到b页面了
b.php
echo $_POST['test'];
打印a提交过来的数据,如果有数据你就自己写sql语句存入数据库就好了
可以使用sock函数实现向另外一个URL POST数据,并获取返回的结果,sockopen提交POST数据例:
$sock = fsockopen("localhost", 80, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)\n");
$data = "txt=" . urlencode("中") . "bar=" . urlencode("Value for Bar");
fwrite($sock, "POST /posttest/response.php HTTP/1.0\r\n");
fwrite($sock, "Host: localhost\r\n");
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, "$data\r\n");
fwrite($sock, "\r\n");
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
echo "\n";
$body = "";
while (!feof($sock))
$body .= fgets($sock, 4096);
fclose($sock);
echo $body;
资料引用:
利用表单提交,范例代码如下:
!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" (这里是新增的)
tr
td valign="top" height="110"兴趣特长:/td
tdtextarea name="content" rows="6" class="textarea0" style="width:630px" /textarea/td
/tr
tr
td valign="top"自我评价:/td
tdtextarea name="content" rows="6" class="textarea0" style="width:630px" /textarea/td
/tr
tr
td colspan="2" align="center"input type="submit" value="提交" //td
/tr
/form (这里是新增的)
/table
/body
/html
一、php配置MySQL
1、将php安装目录下的php_mysql.dll和MySQL安装目录下的libmysql.dll文件拷贝至c:/windows/system32中;
2、配置php.ini
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
把上面四个。dll的最前面的;去掉
二、php表单提交至数据库的实现过程
1、login.php页面
SPAN style="FONT-SIZE: 14px"html
FORM method=post action=add.php
Name: INPUT name=usernameBR
Email: INPUT name=emailBR
INPUT value=提交 type=submit name=submit
/FORM
/SPAN
2、add.php页面
SPAN style="FONT-SIZE: 14px"?php
include("conn.php");
?
?php
if(isset($_POST["submit"]))
{
$sql = "insert into users(username, email) values('$_POST[username]', '$_POST[email]')";
mysqli_query($conn, $sql);
echo "添加成功";
}
?/SPAN
3、conn.php页面
SPAN style="FONT-SIZE: 14px"?php
$conn = new mysqli("localhost", "root", "159357");
$conn-select_db("db_test");
//mysql_query("set name 'gb2312'");
$conn-set_charset("utf8");
?/SPAN
?php
include("conn.php");
$query="select * from liuyan";
$result=mysql_query($query) or die("查询数据失败");//执行查询
if (!empty($_POST) {//当表单有提交东西来时,才执行插入
@$content=htmlspecialchars($_POST['content']);
$lastday=date('Y')."-".date('m')."-".date('d')." ".date('H').":".date('i').":".date('s');
$query1="insert into liuyan(id,content,lastday)values ('','$content','$lastday')";
$result=mysql_query($query1);
if($result){
echo "发表成功!";}
}
?