Php 这个逻辑有什么问题吗
我是初学者。我正在写一页。我有以下代码。但是回声没有给出任何回应。帐号输入的名称是html表单上的accountNumber i、 ePhp 这个逻辑有什么问题吗,php,html,Php,Html,我是初学者。我正在写一页。我有以下代码。但是回声没有给出任何回应。帐号输入的名称是html表单上的accountNumber i、 e 输入附件编号 去 以及go.php页面 <?php error_reporting(E_ALL | E_WARNING | E_NOTICE); ini_set('display_errors', TRUE); if (session_status() == PHP_SESSION_
输入附件编号
去
以及go.php页面
<?php
error_reporting(E_ALL |
E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(!isset($_SESSION['login']))
{
echo ("
<script>location.href='../clogin/'</script>");
die();
}
if (isset($_POST['submit']))
{
include_once('db.php');
//get post details from user
$accountNumber = $_POST['accountNumber'];
$sql = "select * from customer
where account_number = '$accountNumber' ";
$result = mysqli_query($connection,$sql);
if(!$result)
{
die('ERROR:' . mysqli_error($connection));
}
if ($result->num_rows>0)
{
while($row = mysqli_fetch_assoc($result))
{
if ($accountNumber !== $row['account_number')
{
echo"invalid";
}
else
{
echo"valid";
}//end of while
}// end of result count
}// end submit
?>
您的按钮应该由名称
组成,因为发布
和获取
方法基于此工作
应该是
<form action="go.php" method="post">
<label>Enter Acc. No</label>
<input type="number" name="accountNumber" required>
<button type="submit" name="submit">GO</button>
输入附件编号
去
注意:请使用准备好的语句来防止SQL注入警告:您的代码容易受到SQL注入攻击。您应该使用参数化查询和准备好的语句来帮助防止攻击者使用恶意输入值破坏您的数据库。给出了风险的解释,以及如何使用PHP/mysqli安全地编写查询的一些示例。切勿将未初始化的数据直接插入SQL。按照现在编写代码的方式,有人很容易窃取、错误地更改甚至删除您的数据。还包含使用mysqli编写安全SQL的好例子。参数化查询还将大大降低由于未转义的输入值而导致意外语法错误的风险。将name=“submit”
添加到按钮表单,当您可以使用php(如header('location:yourpage.php')时,为什么要使用脚本位置代码>?请学习如何使用prepare stmt来防止sql注入。在$row['account\u number'
上,您忘记了]
非常感谢。我会改正的
<form action="go.php" method="post">
<label>Enter Acc. No</label>
<input type="number" name="accountNumber" required>
<button type="submit" name="submit">GO</button>