我只想说,这里很可能会变得相当简单。
我正在一个网站上工作,用户基本上填写一个表单,其中包含一些数据,这些数据在提交时被发送(GET)到另一个 php 页面,该页面在标题下方包含我的 db-connection 脚本,然后继续执行INSERT 形式的 SQL 查询。此页面仅显示为空白。如果没有 mysql_error(),我有一些应该显示的 html 元素。
这是页面的样子,我在这里做错了什么?
<?php
include '/partials/header.php';
include '/functions/db_connection.php';
if(isset($_POST['value0'])) {
$value0 = mysql_real_escape_string($_POST["value0"]);
$value1 = mysql_real_escape_string($_POST["value1"]);
$value2 = mysql_real_escape_string($_POST["value2"]);
$value3 = mysql_real_escape_string($_POST["value3"]);
$value4 = mysql_real_escape_string($_POST["value4"]);
$value5 = date("d-m-Y");
$query = "INSERT INTO db.my_table(value0, value1, value2, value3, value4, value5, value6, value7)
VALUES ('. $value0 .',
'. $value1 .',
'. $value2 .',
'. $value3 .',
'. $value4 .',
'. $value5 .',
'enum-value',
'. $value7 .');";
$result = mysql_query($query);
if(!$result)
{
//something went wrong, display the error
echo 'Congratulations, something went wrong. You are officially retarded.<br /><br />' . mysql_error();
$sql = "ROLLBACK;";
$result = mysql_query($sql);
}
else
{
$sql = "COMMIT;";
$result = mysql_query($sql);
?>
<div class="box">
<h1 class="green">That's it!</h1>
<p>Let's do some more novice php scripting.</p>
</div>
<?php
}
}
?>
这是我的连接文件:
<?php
$server = "servername";
$userName = "username";
$password = "password";
$db = "db";
$con = mysql_connect($server,$userName,$password,$db);
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>