我写了一些 PHP/sql,目的是将会话变量存储到 SQL 表中。(我遗漏了一些告诉用户 php 有效的 html。)
<?php
session_start();
$name = $_REQUEST["name"];
$type = $_REQUEST["type"];
$lengthnum = $_REQUEST["lengthnum"];
$rewardnum = $_REQUEST["rewardnum"];
$itemreward = $_REQUEST["itemreward"];
$dsn = "mysql:host=localhost;dbname=xxxxxx";
$username = "xxxxxxxxx";
$pw = "xxxxxxxx";
$options = array(PDO ::ATTR_ERRMODE=>PDO ::ERRMODE_EXCEPTION);
try
{
$my_pdo = new PDO ($dsn, $username, $pw, $options);
$sql_stmt = "INSERT INTO xxxxxx (Name, Type, Length, Reward, Item)
VALUES ($name, $type, $lengthnum, $rewardnum, $itemreward)";
$my_pdo->query($sql_stmt);
}
catch(Exception $a)
{
echo "<p>Error..." . $a->getMessage() . "</p>";
}
?>
出于某种原因,这段代码在 "$options = array(" 之后从 php 标签中“中断”,并将其输出到 html 文件。
PDO ::ERRMODE_EXCEPTION); try { $my_pdo = new PDO ($dsn, $username, $pw, $options); $sql_stmt = "INSERT INTO simpleWFA (Name, Type, Length, Reward, Item) VALUES ($name, $type, $lengthnum, $rewardnum, $itemreward)"; $my_pdo->query($sql_stmt); } catch(Exception $a) { echo "
Error..." . $a->getMessage() . "
"; } ?>
谢谢!