使用 if

分享于2022年07月17日 if-statement isset mysql php post 问答
【问题标题】:使用 if(isset($_POST['submit'])) 在脚本打开时不显示回显不起作用(Using if(isset($_POST['submit'])) to not display echo when script is open is not working)
【发布时间】:2022-04-21 20:01:18
【问题描述】:

我的 if(isset($_POST['submit'])) 代码有点问题。我想要的是在脚本打开时不会出现一些回声和表格,但我确实希望它在单击表单的提交按钮时显示。问题是当我包含 if(isset($_POST['submit'])) 函数时,当我单击提交按钮时,它根本不显示回声和表格。这是为什么,请您帮我解决这个问题。

下面是代码:

    



Exam Interface




NOTE: If a search box is left blank, then the form will search for all data under that specific field

Session ID:

Module Number:

Teacher Username:

Student Username:

Grade:

Order Results By:

Your Search: Session ID: "; if (empty($sessionid))echo "'All Sessions'"; else echo "'$sessionid'";echo ", Module ID: "; if (empty($moduleid))echo "'All Modules'"; else echo "'$moduleid'";echo ", Teacher Username: "; if (empty($teacherid))echo "'All Teachers'"; else echo "'$teacherid'";echo ", Student Username: "; if (empty($studentid))echo "'All Students'"; else echo "'$studentid'";echo ", Grade: "; if (empty($grade))echo "'All Grades'"; else echo "'$grade'"; "

"; echo "

Number of Records Shown in Result of the Search: $num

"; echo ""; while ($row = mysql_fetch_array($result)){ echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Student Id Forename Session Id Grade Mark Module Teacher
" . $row['StudentId'] . "" . $row['Forename'] . "" . $row['SessionId'] . "" . $row['Grade'] . "" . $row['Mark'] . "" . $row['ModuleName'] . "" . $row['TeacherId'] . "
"; } mysql_close(); ?>

任何帮助将不胜感激,谢谢。


【解决方案1】:

您需要为您的提交 <input> 命名,否则将无法使用 $_POST['submit']

  • 参数 'name' 来自输入,不是 'value' 而不是 'class' ,例如 -> $_POST['TEST']; ...重要的“名称”...更容易 =)