我已经创建了一个基本表单和一个存储过程来插入数据。该 连接到数据库测试成功,但当我完成表单 我得到这个错误:
- 连接失败:SQLSTATE [42S22]:找不到列:1054未知列' jobbob'在' where子句'
以下是我的一些代码。
<html>
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body>
<?PHP
if(isset($_POST['submit'])) {
$username = $_REQUEST['username'];
$password= $_REQUEST['password'];
$forename = $_REQUEST['forename'];
$surname = $_REQUEST['surname'];
$address_line1 = $_REQUEST['address_line1'];
$address_line2 = $_REQUEST['address_line2'];
$address_line3 = $_REQUEST['address_line3'];
$city = $_REQUEST['city'];
$postcode = $_REQUEST['postcode'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$servername = "localhost";
$dbusername = "user";
$dbpassword = "password";
$dbname = "library";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername,
$dbpassword);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
$sql1="select user_id from users where username=$username";
$result=$conn->query($sql1);
if (empty($result[0])) {
$sql ="CALL add_user(['forename'], ['surname'], ['address_line1'],
['address_line2'], ['address_line3'], ['city'], ['postcode'], ['phone'],
['email'],['username'], ['password'])";
$conn->db_query($sql);
$conn = null;
} else {
echo "Username taken";
}
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
}
?>
<div>
<form action="registrationpage.php" method="post">
First Name: <input type="text" name="forename"> <br />
Last Name: <input type="text" name="surname"> <br />
Address_line1: <input type="text" name="address_line1"><br />
Address_line2: <input type="text" name="address_line2"><br />
Address_line3: <input type="text" name="address_line3"><br />
City: <input type="text" name="city"><br />
Postcode: <input type="text" name="postcode"><br />
Phone <input type="text" name="phone"><br />
Email: <input type="text" name="email"><br />
Username: <input type="text" name="username"><br />
Password: <input type="password" name="password"><br />
Confirm Password: <input id="password" type="password" name="password">
<br/>
<input type="submit" value="Register" name="submit">
</form>
</div>
</body>
</html>
如何解决这个问题?