首页 \ 问答 \ 未定义的索引通知('Undefined index notice')

未定义的索引通知('Undefined index notice')

欢迎,

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

注意:未定义的索引:第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>
....

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

数据库看起来像这样:

在此处输入图像描述

我赞成任何一种帮助:)


I just trying to get a value from the row, but it's not happening and I only get a notice which says:

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

Maybe something is wrong with the syntax? Or the method? How do I get the value?

The database looks like this:

Enter image description here

I appreciate any kind of help :)


原文:https://stackoverflow.com/questions/36481769
更新时间:2022-01-19 15:01

最满意答案

尝试使用return $ BS.unpack headers而不是return (headers >>= BS.unpack)

或者如果headers是ByteStrings列表,请尝试return $ map BS.unpack headers头。

除了它碰巧类型检查(我假设BS.unpack headers工作)的事实,这里是一种思考事物的方式:

  • headers是纯粹的价值
  • BS.unpack是一个纯函数
  • headers >>= ...没有意义,因为>>=的LHS需要是monadic计算
  • ... >>= BS.unpack没有意义,因为>>=的RHS需要是一个产生monadic计算的函数
  • BS.unpack headers是我们想要返回的字符串,但它是纯值
  • 因此,我们使用return来将纯值推广为monadic计算

更新:

以下代码显示如果fetchHeader具有类型IO [BS.ByteString] ,那么您的代码将键入check:

import Data.ByteString.Char8 as BS

fetchHeader :: IO [BS.ByteString]   -- this works
-- fetchHeader :: IO BS.ByteString  -- this doesn't
fetchHeader = undefined

foo :: IO String
foo = do
  headers <- fetchHeader
  return $ headers >>= BS.unpack

另一方面,如果您将其类型更改为IO BS.ByteString ,则会遇到您遇到的错误。

更新2

有趣的是,当headers是ByteStrings的列表时,表达式headers >>= BS.unpack确实有意义并且相当于:

concat $ map BS.unpack headers

Try using return $ BS.unpack headers instead of return (headers >>= BS.unpack).

Or try return $ map BS.unpack headers if headers is a list of ByteStrings.

Besides the fact that it happens to type check (and I'm assuming BS.unpack headers works), here's a way to think about things:

  • headers is a pure value
  • BS.unpack is a pure function
  • headers >>= ... doesn't make sense because the LHS of >>= needs to be a monadic computation
  • ... >>= BS.unpack doesn't make sense because the RHS of >>= needs to be a function which produces a monadic computation
  • BS.unpack headers is the string we want to return, but it's a pure value
  • we therefore use return to promote the pure value to a monadic computation

Update:

The following code shows that if fetchHeader has type IO [BS.ByteString], then your code will type check:

import Data.ByteString.Char8 as BS

fetchHeader :: IO [BS.ByteString]   -- this works
-- fetchHeader :: IO BS.ByteString  -- this doesn't
fetchHeader = undefined

foo :: IO String
foo = do
  headers <- fetchHeader
  return $ headers >>= BS.unpack

On the other hand, if you change its type to IO BS.ByteString you get the error you encountered.

Update 2:

Interestingly enough, when headers is a list of ByteStrings, the expression headers >>= BS.unpack does make sense and is equivalent to:

concat $ map BS.unpack headers

相关问答

更多
  • 有两个单独的ByteString模块,一个用于惰性ByteStrings,另一个用于严格的ByteStrings。 simpleHTTP返回一个惰性字节串,但你导入了strict bytestring模块,因此unpack期望一个严格的字节串。 尝试改变 import qualified Data.ByteString.Char8 as BS 至 import qualified Data.ByteString.Lazy.Char8 as BS 也就是说,如果使用字节串模块的Char8版本,则需要小心, ...
  • 通常,您使用ByteString#toString(Charset)将ByteString转换为String。 此方法允许您指定文本编码的字符集。如果它是UTF-8,您还可以使用方法toStringUtf8()作为快捷方式。 但是,从您的问题来看,听起来您实际上想要使用C风格的三位八进制转义生成转义格式。 AFAIK没有公共功能可以执行此操作,但您可以在此处查看代码 。 您可以将该代码复制到您自己的项目中并使用它。 Normally, you'd convert a ByteString to a Stri ...
  • 正如其他人所说,并不是ByteString速度很快,而是String非常慢。 一个ByteString存储每个字符一个字节,加上一些记账开销。 一个String存储的东西像每个字符12字节(取决于你是在32位还是64位模式下运行)。 它还将每个字符存储在非连续内存中,因此每个字符都必须分配空间,由垃圾回收器单独扫描,并最终单独重新分配。 这意味着糟糕的缓存局部性,大量的分配器时间以及大量垃圾收集时间。 总之,这是非常低效的。 基本上, ByteString完成C所做的事情,Java所做的事情,C ++所做的 ...
  • ByteStrings主要用于二进制数据,但如果您需要的是ASCII字符集,它们也是处理文本的有效方式。 如果需要处理unicode字符串,则需要使用Text 。 但是,我必须强调,它们都不是另一个替代,它们通常用于不同的东西:当Text表示纯unicode时,您仍然需要对二进制ByteString表示进行编码,无论何时通过套接字或文件。 这是一篇关于unicode的基础知识的好文章,它解释了unicode代码点( Text )和编码的二进制字节( ByteString )的关系: 一个绝对最小的每个软件开 ...
  • 正如KA Buhr指出的那样,在将ByteString转换为Uint8ClampedArray ,您可以将该newImageData数组传递给newImageData以获取所需的ImageData对象。 您可以使用内联JavaScript函数来生成Uint8ClampedArray 。 要通过Javascript FFI传递ByteString ,请使用Data.ByteString.useAsCStringLen 。 下面的代码显示了如何执行此操作。 {-# LANGUAGE OverloadedStri ...
  • 尝试使用return $ BS.unpack headers而不是return (headers >>= BS.unpack) 。 或者如果headers是ByteStrings列表,请尝试return $ map BS.unpack headers头。 除了它碰巧类型检查(我假设BS.unpack headers工作)的事实,这里是一种思考事物的方式: headers是纯粹的价值 BS.unpack是一个纯函数 headers >>= ...没有意义,因为>>=的LHS需要是monadic计算 ... > ...
  • 如果您向我们展示您编写的无效代码,这将非常有用。 无论如何,你是在do一个块,并写了这样的东西,是吗? main = do ... writeFile "some-file.txt" (show generateRandomNumberSomehow) ... 你应该做这样的事情: main = do ... randomNumber <- generateRandomNumberSomehow writeFile "some-file.txt" (show ...
  • 首先, Data.ByteString.Char8是一个模块,而不是一个类型。 与Data.ByteString.Lazy相同。 也就是说,假设显而易见,那么注意Data.ByteString.Char8.ByteString实际上是Data.ByteString.Char8.ByteString的重新导出。 所以你需要的是Mikail Glushenkov提到的fromStrict函数。 First of all, Data.ByteString.Char8 is a module, not a type ...
  • 如果可能,使用read会将字符串中的类型转换为适当的类型 使用show会将整数转换为它的字符串表示形式 arg <- getLine let num = pizzas (read arg) putStrLn $ "You will need to order " ++ (show num) ++ " pizzas." 或者这样做: arg <- readLn :: IO Int let num = pizzas arg putStrLn $ "You will need to order " ++ (sh ...
  • fmap教纯粹的函数如何用不纯的输入来fmap : fmap :: (a -> b) -> IO a -> IO b 和(=<<)教授不纯的函数如何用不纯的输入进行调整: (=<<) :: (a -> IO b) -> IO a -> IO b 当然,在ghci中,有一个方便的do notation可以用作(=<<)的简写,所以如果你写 > x <- Data.ByteString.readFile "/path/to/image.jpg" 那么你将在会话的其余部分绑定x :: ByteString ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)