<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html>
<head>
</head>
<body>
<form method="POST">
<?php
//create connection
$dbh = new PDO('mysql:host=localhost;dbname=test', "root", "");
if(isset($_POST["add"])){
$username = $_POST["username"];
$password = $_POST["password"];
$std =$dbh->prepare("insert into new2 (username,password) values(?,?)");
$std->bindParam(1,$username);
$std->bindParam(2,$password);
$std->execute();
}
?>
username: <br />
<input type="text" name="useraname" />
<p>
password: <br />
<input type="text" name="password" />enter code here
<input type="submit" name="add" value="Add" />
</form>
</body>
</html>
这会导致以下错误:
Undefined index: username in C:\wamp\www\bist\addtonew2.php on line 11
此类错误的原因是什么?我只是想在new2
表中插入一些数据。