[英]Undefined variable: id PHP
Can every explain or show me why i'm getting this Undefined variable: id. 每个人都可以解释或告诉我为什么我得到这个未定义的变量:id。
The function 功能
public function getByEmbedId($id, $lang=null){
$id = mysql_real_escape_string($id);
$embed = array();
$e = mysql_query("SELECT * FROM movie_embeds WHERE id='$id'") or die(mysql_error());
if (mysql_num_rows($e)>0){
$movie = $this->formatEmbedData(mysql_fetch_assoc($e), $lang);
}
return $embed;
}
And calling the function. 并调用该函数。
<?php
$embed = $movie->getByEmbedId($id,$language);
if (empty($embed)){
$embed = '';
} else {
$smarty->assign("embed",$embed);
}
?>
If someone can help me out it would be most appreciated 如果有人可以帮助我,将不胜感激
Check your $id
whether it is set or not before calling your function. 在调用函数之前,请检查
$id
是否已设置。 Do like this 像这样
<?php
if(isset($id)) // Make use of the isset construct here
{
$embed = $movie->getByEmbedId($id,$language);
if (empty($embed)){
$embed = '';
} else {
$smarty->assign("embed",$embed);
}
}
?>
when you call $embed = $movie->getByEmbedId($id,$language);
当您调用
$embed = $movie->getByEmbedId($id,$language);
, are $id
and $language
variables defined before ? ,
$id
和$language
变量之前定义过吗?
在函数中使用变量$ id之前,应先声明该变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.