未定义的索引通知('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:
I appreciate any kind of help :)
原文:https://stackoverflow.com/questions/36481769
最满意答案
尝试使用
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 ofreturn (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 valueBS.unpack
is a pure functionheaders >>= ...
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 computationBS.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 computationUpdate:
The following code shows that if
fetchHeader
has typeIO [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 expressionheaders >>= 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版本,则需要小心, ...
-
如何在java中将Protobuf ByteString转换为String(How to Convert Protobuf ByteString to String in java)[2023-03-14]
通常,您使用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 ++所做的 ...
-
文字或测试(Text or Bytestring)[2022-08-16]
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 ...