PHP随机打印php标签内的代码

时间:2013-05-19 01:32:41

标签: php mysql sql session-variables

我写了一些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>";
}
?>

出于某种原因,这段代码&#34;打破&#34; &#34; $ options = array之后的php标签(&#34;并输出到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() . "
"; } ?>

谢谢!

1 个答案:

答案 0 :(得分:0)

只是猜测,但我会说你的数组定义无效。

$options = array(PDO ::ATTR_ERRMODE=>PDO ::ERRMODE_EXCEPTION);

应该是

$options = array("PDO::ATTR_ERRMODE"=>"PDO::ERRMODE_EXCEPTION");