未定义的索引通知

时间:2016-04-07 16:14:35

标签: php mysql mysqli

欢迎,

我只是试图从行中获取一个值,但它没有发生,我只收到一条通知说:

  

注意:未定义的索引:第16行的D:\ xampp \ htdocs_header.php中的sm_value

<?php

require "./conf/db.php"; // Aditional 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 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>
....

语法可能有问题?或方法,我如何得到价值?

数据库如下所示:

enter image description here

我赞美任何形式的帮助:)

1 个答案:

答案 0 :(得分:1)

当您的表单未提交时,会发生这种情况,

所以你需要在你的陈述之前加上一个条件,就像这样。

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.
}