我有一个php脚本如下:
function addPost(BlogPost $item, $tags) {
$connection = mysql_connect('localhost', '***', '***') or die(mysql_error());
mysql_select_db('jschaible1') or die(mysql_error());
$queryString = "insert into BlogPost values ( null, '" . $item->Title . "', '" . $item->Body . "', " . "now());";
$result = mysql_query($queryString) or die(mysql_error());
$dbResult = mysql_query('select * from blogpost where Title = "' . $item->Title . '";') or die(mysql_error());
while ($row = mysql_fetch_array($dbResult)) {
$tableID = $row['BlogPostID'];
}
foreach($tags as $t) {
$queryString = "insert ignore into Tag values('" . strtolower($t) . "');";
mysql_query($queryString) or die(mysql_error());
$queryString = "insert into blogposttag values (" . $tableID . ", '" . strtolower($t) . "');";
mysql_query($queryString) or die(mysql_error());
}
echo $connection;
mysql_close($connection) or die(mysql_error());
}
该函数的调用方式如下:
<?php
session_start();
$errors = '';
if (!isset($_SESSION['dadfg6d5f6df54']))
header('Location:admin.php');
else {
include('Classes.php');
include('mySql.php');
include('utils.php');
if(isset($_POST['Submit'])) {
if ($_POST['Title'] == '') {
$errors = 'Post must have a title!';
}
else if ($_POST['PostBody'] == '') {
$errors = 'Post must be something!';
}
else if (strlen($_POST['PostBody']) < 10) {
$errors = "Write something substantial, c'mon!";
}
else if ($_POST['Tags'] == '') {
$errors = "At least one tag must be entered";
}
else {
$newPost = new BlogPost(NULL, sanitize($_POST['Title']), sanitize($_POST['PostBody']), NULL);
$newPost->Title = addEmoticons($newPost->Title);
$newPost->Body = addEmoticons($newPost->Body);
$tags = str_replace(',', '', $_POST['Tags']);
$tags = str_replace(';', '', $tags);
$tags = explode(' ', $tags);
error_reporting(E_ALL); ini_set('display_errors', 1);
addPost($newPost, $tags) or die();
$errors = 'Post added successfully';
}
}
}
?>
当它到达 mysql_close() 时,页面停止执行,我得到一个空白页面。这真的让我很沮丧,我完全不明白为什么会这样,尤其是看到 PREVIOUS 行上的回声如何输出“资源 id#6”。我没有收到错误消息,只是一个空白页!请帮忙!