php - 将 PHP 表单连接到 MySQL 问题
问题描述
我正在尝试在这里学习新事物,但我从未使用过 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:\inetpub\wwwroot\create.php:3
Stack trace:
#0 {main}
thrown in `C:\inetpub\wwwroot\create.php on line 3`
同样,我对此很陌生,我正在尽我所能理解这一点。
解决方案
您的第一行包含一个错字。它应该是:
if (isset($_POST['submit']))
你那里有一个额外的'e'。
推荐阅读
- python - 无法在 Visual Studio 代码中使用 tensorflow 和 keras 库
- csv - 在magento 2中的csv导入期间从分组产品中删除简单产品
- c++ - 我应该在 Windows 上使用什么 std::mutex?
- rest - 如何从 Googlefit REST API 获取注册期间给出的高度数据
- ibm-midrange - 如何使用 CPYFRMSTMF 命令将源代码放入 QRPGLESRC 文件
- python - ModuleNotFoundError:在 os.execv 调用中没有名为“模块名称”的模块 - python
- python - Python日志记录模块,日志文件问题:PermissionError:[WinError 32]进程无法访问该文件,因为它正在被另一个进程使用
- javascript - 如何使用 javascript 填充由 Django 创建的 HTML 表?
- arrays - 递归和数组 - 基本情况 - 长度等于 0 或 1
- javascript - 无法读取未定义的属性“getAboutInfo”