Win98+PWS+PHP下Undefined variable的问题 说明没有定义xxxxx,能贴出你的程序吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有点长,是从动网上下载文章管理的,别的很多也有这样的问题。出现的页面错误提示为:X-Powered-By: PHP/4.0.3pl1 Content-type: text/html Warning: Undefined variable: typeid in E:\Inetpub\PHP\Article\index.php on line 11还有很多和上面一样的错误。部分代码如下:<html><head><title>PHP专题|http://asky.on.net.cn</title><link rel="stylesheet" type="text/css" href="style.css"><script language="javascript">function popwin2(id,path){ window.open("list.php?id="+id+"&ppath="+path,"","height=450,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");}</script><?$typeid=htmlspecialchars ( $typeid );if ($typeid==""){ $typeid=1;};$conn = mysql_connect('localhost:3306','root','');mysql_select_db('article');$text = "select*from type where typeid=$typeid ";$rs = mysql_query ($text,$conn);$rom = mysql_fetch_row ($rs);$err=mysql_error();if (! $rom) { echo $err."<br>"; echo "此栏目不存在!!!!"; }else{ $page=htmlspecialchars($page); if ($page==""){ $page=1; }; $type1=$rom[1]; $text="select count(*) as articleid from learning where typeid='$typeid'"; $rs=mysql_query($text,$conn); $pagesize=2; $count=mysql_result($rs,"0","articleid"); if (!$count){…………没有全部给出,太长了。 错误原因:第十一行($typeid=htmlspecialchars($typeid);)函数htmlspecialchars中的参数$typeid没有定义,所以出错,你可以照下面的方法改正。把$typeid=htmlspecialchars ( $typeid );if ($typeid==""){ $typeid=1;};改为:if (not isset($typeid) or $typeid==""){ $typeid=1;}else{ $typeid=htmlspecialchars($typeid);} peakcock:php的环境变量是不是部可以自动引用书上给出的一个计算器例子如下<form action=" <? echo $PHP_SELF ?>" method="post">操作数1:<input type=text name=num1><br>操作数2:<input type=text name=num2><br><p>你希望进行何种操作呢?<br><input type=radio name=operation value="加" checked>加<br><input type=radio name=operation value="减">减<br><input type=radio name=operation value="乘">乘<br><input type=radio name=operation value="除">除<br><input type=submit><input type=reset></form></body></html>结果: <?php echo $num1;?> <?php echo $operation;?> <?php echo $num2;?>等于<br><h1><?phpif ($operation == "除"){$x = $num1 / $num2;print $x;}elseif ($operation == "减"){$x = $num1 - $num2;print $x;}elseif ($operation == "乘"){$x = $num1 * $num2;print $x;}else{$x = $num1 + $num2;print $x;}?></h1>_______________________________第一次运行结果如下: Warning: Undefined variable: num1 in E:\Inetpub\phproot\chapter08\09.PHP on line 15Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 15Warning: Undefined variable: num2 in E:\Inetpub\phproot\chapter08\09.PHP on line 15等于Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 19Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 22Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 25Warning: Undefined variable: num1 in E:\Inetpub\phproot\chapter08\09.PHP on line 29Warning: Undefined variable: num2 in E:\Inetpub\phproot\chapter08\09.PHP on line 290______________________是否一定要初始化变量,另外,书上说没有付值的变量为0或空字符,好像不顶用,运行时总是出现Undefined Variable 估计是你改动了PHP.ini配置文件了,原来的版本有个Track_vars,自动为form传来的数据生成变量($num1,$num2等)不过php4.0以后这个功能就是自动enable的了,另外还有:register_globals,register_argc_argv估计和你的问题也有关。你最好重新copy一个新的Php.ini回去试一试 我检查过了,Track_vars自动enable的,register_globals=onregister_argc_argv=on不知道怎么搞的? 应该不错呀,你的php版本是多少?对php.ini作了哪些改动? mysql 的视图和存储过程的效率? global 变量在大并发环境是线程安全的吗? 如何写 preg_match_all 匹配 url 的正则 ? 最近想看一看PHP内核方面的东西,还望前辈们教教 文本留言第伍问 关于网站中用户身份认证的的一点问题? 急!!!!!!!!! php有没有这个能力:获取某个文件的类型。有哪位知道。甘愿送分。 请问这个PHP调用的MYSQL数据为什么乱码了? 我要炸了。。。。。。。 fgets(int fp, int length)函数中,length参数有什么意义? 看看这个到底是不是真的要用到session??
出现的页面错误提示为:X-Powered-By: PHP/4.0.3pl1 Content-type: text/html
Warning: Undefined variable: typeid in E:\Inetpub\PHP\Article\index.php on line 11
还有很多和上面一样的错误。
部分代码如下:
<html>
<head>
<title>PHP专题|http://asky.on.net.cn</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script language="javascript">
function popwin2(id,path)
{ window.open("list.php?id="+id+"&ppath="+path,"","height=450,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
</script>
<?
$typeid=htmlspecialchars ( $typeid );
if ($typeid==""){
$typeid=1;
};$conn = mysql_connect('localhost:3306','root','');
mysql_select_db('article');
$text = "select*from type where typeid=$typeid ";
$rs = mysql_query ($text,$conn);
$rom = mysql_fetch_row ($rs);
$err=mysql_error();
if (! $rom) {
echo $err."<br>";
echo "此栏目不存在!!!!";
}
else{
$page=htmlspecialchars($page);
if ($page==""){
$page=1;
};
$type1=$rom[1];
$text="select count(*) as articleid from learning where typeid='$typeid'";
$rs=mysql_query($text,$conn);
$pagesize=2;
$count=mysql_result($rs,"0","articleid");
if (!$count){
…………
没有全部给出,太长了。
if ($typeid==""){
$typeid=1;
};改为:if (not isset($typeid) or $typeid==""){
$typeid=1;
}
else{
$typeid=htmlspecialchars($typeid);
}
书上给出的一个计算器例子如下
<form action=" <? echo $PHP_SELF ?>" method="post">
操作数1:<input type=text name=num1><br>
操作数2:<input type=text name=num2><br>
<p>
你希望进行何种操作呢?<br>
<input type=radio name=operation value="加" checked>加<br>
<input type=radio name=operation value="减">减<br>
<input type=radio name=operation value="乘">乘<br>
<input type=radio name=operation value="除">除<br>
<input type=submit><input type=reset></form>
</body>
</html>
结果: <?php echo $num1;?> <?php echo $operation;?> <?php echo $num2;?>
等于<br>
<h1>
<?php
if ($operation == "除")
{$x = $num1 / $num2;
print $x;}
elseif ($operation == "减")
{$x = $num1 - $num2;
print $x;}
elseif ($operation == "乘")
{$x = $num1 * $num2;
print $x;}
else
{$x = $num1 + $num2;
print $x;}
?>
</h1>
_______________________________
第一次运行结果如下:
Warning: Undefined variable: num1 in E:\Inetpub\phproot\chapter08\09.PHP on line 15
Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 15
Warning: Undefined variable: num2 in E:\Inetpub\phproot\chapter08\09.PHP on line 15
等于
Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 19
Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 22
Warning: Undefined variable: operation in E:\Inetpub\phproot\chapter08\09.PHP on line 25
Warning: Undefined variable: num1 in E:\Inetpub\phproot\chapter08\09.PHP on line 29
Warning: Undefined variable: num2 in E:\Inetpub\phproot\chapter08\09.PHP on line 29
0
______________________
是否一定要初始化变量,另外,书上说没有付值的变量为0或空字符,好像不顶用,运行时总是
出现Undefined Variable
原来的版本有个Track_vars,自动为form传来的数据生成变量($num1,$num2等)
不过php4.0以后这个功能就是自动enable的了,另外还有:register_globals,register_argc_argv估计和你的问题也有关。
你最好重新copy一个新的Php.ini回去试一试
register_globals=on
register_argc_argv=on
不知道怎么搞的?