gpt4 book ai didi

php - 向mysql表中插入数据表格

转载 作者:行者123 更新时间:2023-11-30 00:29:55 26 4
gpt4 key购买 nike

有人告诉我哪里出了问题

html代码是:

<form action="insert.php" method="POST">
<label>Firstname:</label> <input type="text" name="firstname" value="first name" /><br />
<label>Lastname:</label> <input type="text" name="lastname" value="last name" /><br />
<label>email:</label> <input type="text" name ="email" value="email" /><br />

php 代码是:

<?php
if(isset($_POST['submit'])!='')
{
$fname=$_POST ['firstname'];
$lname=$_POST ['lastname'];
$email=$_POST ['email'];
mysql_connect ("localhost","root","mydatabase") or die (mysql_error ());
mysql_select_db ("my_db") or die (mysql_error ());
mysql_query ("ISERT INTO userinfo (`firstname`,`lastname`,`email`)
VALUES ('$fname','$lname','$email')");
echo "successfully updated" ;
}

?>

最佳答案

这是INSERT而不是ISERT..你有一个拼写错误

mysql_query ("ISERT INTO userinfo (`firstname`,`lastname`,`email`)
^^^^^

修改后的代码..

<?php
if(isset($_POST['submit'],$_POST['firstname'],$_POST ['lastname'],$_POST ['email']))
{
$fname=$_POST['firstname'];
$lname=$_POST['lastname'];
$email=$_POST['email'];
mysql_connect ("localhost","root","mydatabase") or die (mysql_error ());
mysql_select_db ("my_db") or die (mysql_error ());
$result=mysql_query ("INSERT INTO userinfo (`firstname`,`lastname`,`email`)
VALUES ('$fname','$lname','$email')");
if($result){ echo "Successfully Updated" ; } else {die(mysql_error());}
}
<小时/>

此(mysql_*) 扩展自 PHP 5.5.0 起已弃用,并将在将来删除。相反,应使用 MySQLiPDO_MySQL 扩展。切换到 PreparedStatements 可以更好地抵御 SQL 注入(inject)攻击!

关于php - 向mysql表中插入数据表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22592296/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com