PHP:空白页上显示未定义

标签 php mysql undefined

我正在尝试打印/回显以前文件中的值,但是没有显示错误,而是在空白页上显示的所有内容都是“未定义”。我已经研究并尝试了几种方法,但没有任何效果。请帮忙。

<?PHP
$user_name = "root";
$password = "";
$database = "leadership_program";
$server = "localhost";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

 if (isset($_POST['survey_id'])) {
    $survey_id = $_POST['survey_id'];
   echo $survey_id;
}

if (isset($_POST['marks'])) {
    foreach ($_POST['marks'] as $value) {
        echo"$value";
    }        
}

if (isset($_POST['id'])) {
    $id = $_POST['id'];
    echo $id;
}

// $SQL2 = "UPDATE answer_table SET marks='$value' WHERE survey_id= '$survey_id' AND student_id= '$id'";

//$result2 = mysql_query($SQL2);

//mysql_close($db_handle);


 } else {

    print "Database NOT Found ";
    mysql_close($db_handle);
   // header("Location: surveyView.php");
}
?>

这里是displayresult.php

<form action="student_mark_save.php" method="POST"> //<?php...more codes here

            if ($strucrow["qns$i"] === 'radio' || $strucrow["qns$i"] === 'checkbox') {

                foreach ($arr as $b) {

                    echo "<br/>";

                    if (strpos($b, '%#%') !== false) {
                        $c = substr($b, 3, -2);
                        //echo $c;
                        $d = str_replace("$arr[0] :-", ':', $c);
                        echo $d, "<br/>";
                        echo "<br/>";

                        echo "<tr> Marks : <input type=\"text\" name=\"marks[]\"></tr><br />";

                        //echo $b;
                    } else {
                        echo $b;
                        // echo "is not with comment qns";
                    }
                }
            } else if ($strucrow["qns$i"] === 'comment') {

                foreach ($arr as $b) {

                    echo $b;

                    echo "<tr> Marks : <input type=\"text\" name=\"marks[]\"></tr><br />";
                    // echo "is not with comment qns";
                }

            } else {

            }
            echo "<p/>";
        }

        $marksquery = sprintf(
                "SELECT marks FROM answer_table WHERE survey_id = '%d' AND student_id = '$studentid' ", mysql_real_escape_string($survey_id)
        );
        $marksQuer = mysql_query($marksquery) or die(mysql_error());

        $marksrow = mysql_fetch_assoc($marksQuer);

         echo "<td><input type=\"hidden\" value= \"$survey_id\" name=\"survey_id\"></td><br />" ;
         echo "<td><input type=\"hidden\" value= \"$studentid\" name=\"id\"></td><br />" ;

         echo "<p><input type=\"submit\" value=\"Update\"></p>";
        ?> 


        </form>

最佳答案

对于未定义的意思,全局$_POST[]中不存在某些东西 检查尝试在您的第一个 if 语句中打印 $_POST 为:

if ($db_found) {

     print_r($_POST);
     exit();      

 if (isset($_POST['survey_id'])) {
    $survey_id = $_POST['survey_id'];
   echo $survey_id;
}

现在看看你在$_POST中有什么,它可能对你有帮助...谢谢

关于PHP:空白页上显示未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20922957/

相关文章:

PHP 网络服务 : Get Multiple Records from MySQL and encode it in JSON array

php - 从 2 个不同的表以用户或管理员身份登录

MySQL SELECT COUNT DISTINCT 来自 2 列

mysql - 加入表和字符串比较(大数据集)

javascript - 安全合并 JavaScript 子属性

c - 我无法弄清楚为什么在我的头文件中调用方法时出现 undefined reference 问题

javascript - Uncaught ReferenceError : function is not defined - Wordpress specific issue

php - 使用自定义规则验证 Laravel 数组

php 函数回显 javascript 字符串

Javascript Jquery JSON 发布 - 我的理解正确吗?