donglu8344812 2013-03-20 21:39
浏览 43
已采纳

PHP回显显示空白屏幕的变量

So I have the following PHP code

<?php 

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

    $poscote = $_POST['postcode'];

    mysql_real_escape_string($poscote);

    //! Checks for direct access to page

    if (empty($_POST)) {
        header('location:index.php?nothingentered');
        die();
    }


    require_once('../Connections/PropSuite.php'); 


    mysql_select_db($database_Takeaway, $Takeaway);
    $query_PC = "SELECT * FROM Postcodes WHERE pc = '$postcode'";
    $PC = mysql_query($query_PC, $Takeaway) or die(mysql_error());
    $row_PC = mysql_fetch_assoc($PC);

    if( mysql_errno() != 0){
     // mysql error
     // note: message like this should never appear to user, should be only stored in log
     echo "Mysql error: " . htmlspecialchars( mysql_error());
     die();
     }

    else {

    echo $row_PC['oc'];

    }

?>

This is to process a form with the following code

<form action="search_postcode.php" method="post">
        <input type="text" name="postcode" />
        <button>Go</button>
    </form>

Strangely its just showing a blank screen, no errors, nothing I have checked through and cannot seem to find a solution.

Many thanks in advance for your help.

  • 写回答

3条回答 默认 最新

  • dongmai6666 2013-03-20 21:44
    关注

    As your $postcode variable is undefined, you are looking in your database for a row where pc is an error message.

    That query could very well finish without errors, but it probably produces 0 rows, so you don't have an error, nor do you have a result. In that case you output nothing, so you will see a blank screen.

    You probably want:

    $postcode = mysql_real_escape_string($poscote);
    

    instead of:

    mysql_real_escape_string($poscote);
    

    and put it below the database connection section.

    Also, you should switch to PDO (or mysqli) and prepared statements to avoid sql injection problems and because the mysql_* functions are deprecated. Note that your mysql_real_escape_string does not do anything (except removing the contents of your variable...) when you don't have a database connection open.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))