我只是想从行中获取一个值,但它没有发生,我只收到一条通知,上面写着:
Notice: Undefined index: sm_value in D:\xampp\htdocs_header.php on line 16
<?php
require "./conf/db.php"; // Additional data
session_start();
if (isset($_SESSION["UserID"])) {
}
else {
header('Location: login.php?=redirect');
}
// If user click to logout
if (isset($_GET["account"]) && $_GET['account'] == "logout") {
unset($_SESSION["UserID"]);
session_destroy();
header("Location: index.php"); // Redirect him/her to index.php
exit();
}
$name = mysqli_escape_string($mysqli, $_POST['sm_value']);
$GetTitle = $mysqli->query("select * from sm_options where sm_value='$name'");
$row = $GetTitle->fetch_array(MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php echo $row['sm_name'];?></title>
....
也许语法有问题?或者方法?如何获取该值?
数据库如下所示:
我感谢任何形式的帮助:)
最佳答案
当您的表单尚未提交时,就会发生这种情况。
因此您需要在语句之前添加一个条件,如下所示:
if(!empty($_POST) and array_key_exists("sm_value", $_POST)) {
$name = mysqli_escape_string($mysqli, $_POST['sm_value']);
$GetTitle = $mysqli->query("select * from sm_options where sm_value='$name'");
$row = $GetTitle->fetch_array(MYSQLI_ASSOC);
// Every statement and HTML which is required under it when the value is not empty
}
else {
// An error message, when you say the details are not available.
}
关于php - “未定义索引通知”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36481769/