Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提交已编辑帖子时,编辑帖子PHP脚本空白屏幕_Php - Fatal编程技术网

提交已编辑帖子时,编辑帖子PHP脚本空白屏幕

提交已编辑帖子时,编辑帖子PHP脚本空白屏幕,php,Php,我最近参与了一个小型的网络开发项目,创建了一个在线投资组合和博客。我一直在摆弄一些PHP代码来编辑网站上的博客文章,这给了我一些问题。其中最大的问题是当我将更改后的帖子提交到数据库时会发生什么。当我提交帖子时,我得到的只是一个空白屏幕,我现在不知所措。如果需要更多信息,请告诉我。提前谢谢 我的尝试: <?php ob_start(); include('db.php'); if(isset($_GET['id'])) { $id=$_GET['id']; if(

我最近参与了一个小型的网络开发项目,创建了一个在线投资组合和博客。我一直在摆弄一些PHP代码来编辑网站上的博客文章,这给了我一些问题。其中最大的问题是当我将更改后的帖子提交到数据库时会发生什么。当我提交帖子时,我得到的只是一个空白屏幕,我现在不知所措。如果需要更多信息,请告诉我。提前谢谢

我的尝试:

<?php 
ob_start(); 
include('db.php'); 
if(isset($_GET['id'])) 
{ 
    $id=$_GET['id']; 
    if(isset($_POST['update'])) 
    { 
        htmlspecialchars($title); 
        htmlspecialchars($content); 
        strip_tags($title); 
        strip_tags($content); 
        $updated= mysql_query("UPDATE blog_entry SET title=$title, content=$content WHERE post_id='$id'")or die(); 
        if($updated) 
        { 
            $msg="Successfully Updated!!"; 
            echo $msg; 
            header('Location:blog.php'); 
        } 
    } 
} //update ends here ob_end_flush(); 
?>

这四行没有效果:

htmlspecialchars($title); 
htmlspecialchars($content); 
strip_tags($title); 
strip_tags($content);
您必须将结果分配给以下内容:

$title   = htmlspecialchars( $title ); 
$content = htmlspecialchars( $content ); 
$title   = strip_tags( $title ); 
$content = strip_tags( $content );
还请注意,对于上述代码,单引号(
)将无法正确转义。考虑使用:

$title   = mysql_real_escape_string( $title ); 
$content = mysql_real_escape_string( $content ); 
然后,必须用单引号将字段值括起来:

$updated = mysql_query( "UPDATE blog_entry SET title='$title', content='$content' WHERE post_id='$id'" ) or die();
#                                                    ↑      ↑          ↑        ↑
为了更好地控制错误,请在
die()中添加一些内容:

请注意: PHP 5.5.0中不推荐使用mysql语法,PHP 7.0.0中删除了mysql语法。相反,应使用扩展名


(来自PHP官方网站)

粘贴您已经尝试过的内容。我意识到这是格式不好的,我道歉
echo$msg;标题('Location:blog.php')即使使用
ob_start(),也不起作用。你不能回音并有标题。它是一个或另一个。请参考以下链接,并将其应用于您的代码。很明显,您没有引用字符串值。您好,谢谢您的帮助。我意识到,前面给出的四行并没有起到任何作用,我忘了在代码中删除它们。我已经调整了代码以包含您建议的更改,但是现在提交帖子时,它会在数据库中插入空白?提前谢谢。我不知道查询和POST变量中有什么。在执行之前打印它。我打印了POST变量,这些变量是空的,所以我所做的是回显title和content变量的内容,然后停止代码。内容是空的。
$updated = mysql_query( ... ) or die( mysql_error() );