我在这里尝试学习新事物,我从未使用过PHP或MySQL。最近,我在我拥有的Linux VM上安装了MySQL,创建了一些帐户,创建了一个数据库,一个表(名字,姓氏,城市,国家,年龄(。
学习了如何将数据输入到我的表中,并开始使用 MySQL 查询插入内容。我很快意识到以这种方式输入所有这些数据是多么无效和耗时。所以我开始研究,并决定在我在同一网络中拥有的Windows 10机器上的IIS之上安装PHP。
使我的SQL数据库可以从我的Windows机器远程访问,我开始按照本指南创建我的网站/表单并将所有内容连接到我已经拥有的MySQL数据库。
一切都很顺利,直到我开始向create.php文件添加代码,尝试在单击提交按钮后将数据插入数据库。
以下是我现在create.php
的样子:
<?php
if (isseet($_POST['submit'])) {
require "../config.php";
try {
$connection = new PDO($dsn, $username, $password, $options);
// insert new user code will go here
$new_user = array(
"firstname" => $_POST['firstname'],
"lastname" => $_POST['lastname'],
"city" => $_POST['city'],
"country" => $_POST['country'],
"age" => $_POST['age']
);
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"users",
implode(", ", array_keys($new_user)),
":" . implode(", :", array_keys($new_user))
);
$statement = $connection->prepare($sql);
$statement->execute($new_user);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
<?php include "templates/header.php"; ?><h2>Add a user</h2>
<form method="post">
<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname">
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="lastname">
<label for="city">City</label>
<input type="text" name="city" id="city">
<label for="country">Country</label>
<input type="text" name="country" id="country">
<label for="age">Age</label>
<input type="text" name="age" id="age">
<input type="submit" name="submit" value="Submit">
</form>
<a href="index.php">Back to home</a>
<?php include "templates/footer.php"; ?>
每次保存并重新加载http://localhost/create.php
时,都会收到以下错误:
PHP Fatal error: Uncaught Error: Call to undefined function isseet() in C:inetpubwwwrootcreate.php:3
Stack trace:
#0 {main}
thrown in `C:inetpubwwwrootcreate.php on line 3`
同样,我对此很陌生,我正在尽最大努力理解这一点。您的第一行包含拼写错误。它应该是:
if (isset($_POST['submit']))
你那里有一个额外的"e"。