【发布时间】:2015-05-23 00:39:03
【问题描述】:
数据库名称:forumTutorial
表名:threads
4 Columns:
id - INT - 5 Length - Primary Key - Auto Increment (AI/A_I).
title - VARCHAR - 255 Length
content - VARCHAR - 2000 Length
author - VARCHAR - 255 Length
我没有收到任何错误.. 它只是说创建失败
<?php
session_start();
//$_SESSION['username'] = 'Admin';
$con = mysqli_connect('localhost', 'root', '', 'forumTutorial') or die(mysql_error());
if (isSet($_POST['createThread'])) {
if (isSet($_POST['title']) && $_POST['title'] != '' && isSet($_POST['content']) && $_POST['content'] != '' && isSet($_SESSION['username']) && $_SESSION['username'] != '') {
$title = $_POST['title'];
$content = $_POST['content'];
$user = $_SESSION['username'];
$q = mysqli_query($con, "INSERT INTO `threads` VALUES ('', '$title', '$content', '$user')");
if ($q) {
echo 'Thread created.';
}else
echo 'Failed to create thread.';
}
}?>
<html>
<head></head>
<body>
<h1>Create Thread:</h1>
<form action='forumTutorial.php' method='POST'>
<table>
<tbody>
<tr>
<td>Title: </td><td><input type='text' name='title' /></td>
</tr>
<tr>
<td>Description: </td><td><input type='text' name='content' /></td>
</tr>
<tr>
<td></td><td><input type='submit' value='Create Thread' name='createThread' /></td>
</tr>
</tbody>
</table>
</form>
</body>
【问题讨论】:
-
您需要添加错误处理,以便您查看问题所在。你可能是 sql 注入自己;你应该切换到准备好的语句。
-
php 区分大小写 isSet 不是函数使用 "isset()" 并且您的查询容易受到 SQL 注入的影响
-
PHP 不区分大小写,你从哪里得到的……只有变量在 php 中区分大小写,函数名、类名,甚至命名空间都不区分大小写,除非在它们的自动加载约束中跨度>
-
感谢指正