dtjzpg5313 2015-08-30 06:17
浏览 43
已采纳

未定义的变量:第115行的C:\ xampp \ htdocs \ shed \ select.php中的列表[重复]

it is working nice.. but when i open the page.. its allways give me this message Undefined variable: list in C:\xampp\htdocs\shed\select.php on line 115

when i submit the page it allways gives me right data.. but allways shows me that undefined variable $list

   <?php
  include("db.php");
  if(isset($_POST['submit']))
  {


    $aa= mysql_real_escape_string($_POST['loco_name']);
    $bb=mysql_real_escape_string ($_POST['section']);

    $result=mysql_query("select * from loco_detail Where loco_name= '$aa' AND section= '$bb' ") or die (mysql_error());




      $Count = mysql_num_rows($result); // count the output amount
     if ($Count > 0)
          {
       while($row = mysql_fetch_array($result))
             { 
         $name = $row["loco_name"];
         $section = $row["section"];
         $schedule = $row["schedule"];
         $repair = $row["repair"];
         $action = $row["action"];

         $date = strftime("%b %d, %Y", strtotime($row["date"]));


     $list .="  


     <table id=\"table\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">
     <tr>
     <td id=\"row\">  $name     </td>
     <td id=\"row\">  $schedule  </td>
      <td id=\"row\">  $repair  </td>
      <td id=\"row\">  $action  </td>
      <td id=\"row\">  $date      </td>
        </tr>
     </table>

     ";      


    }
   } else {
     $list = "You have no products listed in your store yet";
   }



     }



     ?>

here the html code

        <body>



    <center>
     <fieldset>
    <legend>Select</legend>
    <table>
    <form method="post">
    <tr><td>Loco Number:</td><td><input type="text" name="loco_name"/></td></tr>
     <tr><td>Section:</td><td><select name="section">
     <option value="Mechanical">Mechanical</option>
     <option value="Electrical">Electrical</option>
     </select></td></tr>
     <tr><td><input type="submit" name="submit" value="Submit"></td></tr>
     </form>
     </table>
      </fieldset>
     </center>


     <div >

       <?php echo $list; ?>

       </div>


       </body>

please make me out from here.

</div>
  • 写回答

1条回答 默认 最新

  • duandang9434 2015-08-30 06:18
    关注

    There is a period in front of $list which is invoking string concatenation.

    The error message is saying you're trying to use a variable that hasn't been "declared" yet. However these are pretty pointless to fix and just causes you to write a lot more redundant code.

    You can disable these in your php.ini by changing: error_reporting to E_ALL & ~E_NOTICE or adding error_reporting(E_ALL & ~E_NOTICE); to the top of the page

    In a nut shell you're trying to add on to an existing variable called $list that was never declared.

    Example of string concatenation:

    You can read more here: PHP String Operators

    $string = "Hello "; // Declared
    $string .= "World";
    $string .= "!";
    echo $string;
    
    // Outputs "Hello World!"
    

    Basically to fix your issue change your if statement to the following

    if ($Count > 0) {
        $list = ''; 
        while($row = mysql_fetch_array($result)) { 
            $name = $row["loco_name"];
            $section = $row["section"];
            $schedule = $row["schedule"];
            $repair = $row["repair"];
            $action = $row["action"];
            $date = strftime("%b %d, %Y", strtotime($row["date"]));
    
            ob_start();
            ?>
            <table id="table" border="1" cellpadding="2" cellspacing="2">
             <tr>
                <td class="row"><?=$name?></td>
                <td class="row"><?=$schedule?></td>
                <td class="row"><?=$repair?></td>
                <td class="row"><?=$action?></td>
                <td class="row"><?=$date?></td>
                </tr>
            </table>
            <?
            $list .= ob_get_clean();
    
            // rest of code here
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测