怎么将表单中的数据提交到数据库 php
1个回答
展开全部
一、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=username><BR>
Email: <INPUT name=email><BR>
<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>
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=username><BR>
Email: <INPUT name=email><BR>
<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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询