有人告诉我哪里有错误
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" ;
}
&GT;
答案 0 :(得分:0)
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
起已弃用,将来会被删除。相反,应使用MySQLi
或PDO_MySQL
扩展名。切换到PreparedStatements
甚至可以更好地抵御SQL注入攻击!
答案 1 :(得分:0)
试试这个
if ($_POST) {
$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 ("INSERT INTO userinfo (firstname,lastname,email)
VALUES ('$fname','$lname','$email')");
echo "successfully updated" ;
}
在您的示例中,我没有看到$_POST['submit']
并且您错误地使用了INSERT