注意未定义常量假设MySql

时间:2011-07-21 08:47:13

标签: php mysql

这是我的代码,但是在新的迷你康柏笔记本电脑上安装新的wamp服务器之后才运行良好?我收到错误:

$sno=mysql_result($result,$m,"sno");
$name=mysql_resul($result,$m,"name");
$location=mysql_result($result,$m,"location");
$sector=mysql_result($result,$m,"sector");
$status=mysql_result($result,$m,"status");*/?>
<table width="320" border="0"cellspacing="0">
  <tr>
    <strong>   <td width="194"><strong><span class="style16"><font face="Lucida Console, Lucida Sans Unicode">PV NO:</font></span></strong></td>
    <td width="110" nowrap><span class="style16"><strong><?PHP echo "$_POST[pvno]";?></strong></span></td></strong>  </tr>

  <tr>
    <td width="194"><span class="style16"><strong><font face="Lucida Console, Lucida Sans Unicode">SNO</font></strong></span></td>
    <td width="110" nowrap><span class="style16"><?PHP echo ''.$sno.''; ?></span></td>
  </tr>
  <tr>
    <td><span class="style16"><strong><font face="Lucida Console, Lucida Sans Unicode">PROJECT NAME </font></strong></span></td>
    <td nowrap><span class="style16"><strong><?PHP echo $name;?></strong></span></td>
  </tr>
  <tr>
    <td><span class="style16"><strong>SECTOR</strong></span></td>
    <td nowrap><span class="style16"><?PHP echo $sector;?></span></td>
  </tr>
  <tr>
    <td><span class="style16"><strong>CONTRACTOR</strong></span></td>
    <td nowrap><span class="style16"><?PHP echo $contractor;?></span></td>
  </tr>
    <tr>
    <td><span class="style16"><strong>CONTACTS</strong></span></td>
    <td nowrap><span class="style16"><?PHP echo $contact;?></span></td>
  </tr>
  <tr>
    <td><span class="style16"><strong>LOCATION</strong></span></td>
    <td nowrap><span class="style16"><?PHP echo $location;?></span></td>
  </tr>
  <tr>
    <td><span class="style16"><strong>STATUS</strong></span></td>
    <td nowrap><span class="style16"><?PHP echo $status; ?></span></td>
  </tr>
</table>

我得到的输出错误是:

PV NO:  AGRI008
SNO     
Notice: Undefined variable: sno in C:\wamp\www\cdf\new pro\pvsearch.php on line 162
PROJECT NAME    
Notice: Undefined variable: name in C:\wamp\www\cdf\new pro\pvsearch.php on line 166
SECTOR  
Notice: Undefined variable: sector in C:\wamp\www\cdf\new pro\pvsearch.php on line 170
CONTRACTOR  
Notice: Undefined variable: contractor in C:\wamp\www\cdf\new pro\pvsearch.php on line 174
CONTACTS    
Notice: Undefined variable: contact in C:\wamp\www\cdf\new pro\pvsearch.php on line 178
LOCATION    
Notice: Undefined variable: location in C:\wamp\www\cdf\new pro\pvsearch.php on line 182
STATUS  
Notice: Undefined variable: status in C:\wamp\www\cdf\new pro\pvsearch.php on line 186

任何帮助,请在此处输入代码

3 个答案:

答案 0 :(得分:1)

<?PHP echo "$_POST[pvno]";?>

pvno不在引号内,因此将其视为常量,但常量不存在(这正是通知试图告诉您的内容)

使用此代替

<?PHP echo $_POST['pvno'];?>

变量周围没有双引号。

其他

<?PHP echo ''.$sno.''; ?>

这里引用无用

<?PHP echo $sno; ?>

答案 1 :(得分:1)

在你的代码中,我看到);*/?>,女巫意味着顶部的整个php块被注释掉,因此没有变量可以打印出来(因为它们从未被初始化)。

答案 2 :(得分:0)

看起来代码已被注释掉,因此将被忽略。获取一个语法高亮的编辑器,这将使您更容易阅读源代码并找到已注释掉的代码片段。

见这一行:

$status=myslq_result($result,$m,"status");*/?>
                                          ^^ end of a multi-line comment

关于未定义变量的警告仅表示该变量到目前为止尚未初始化。

相关问题