【问题标题】:PHP/HTML Line causing the page to go blank [closed]PHP / HTML行导致页面变为空白[关闭]
【发布时间】:2016-05-23 08:46:02
【问题描述】:

我真的不知道如何解决这个问题。 每次我将这行代码添加到我的 php 文档中时,页面都会变为空白。 有没有人遇到过这个问题?

它在一张桌子上。显然它是 checked_id[] 数组。不知道怎么解决,只是添加时页面变空白。

<td align="center"><input type="checkbox" name='.checked_id[];.' class="checkbox" value='.$row["id"].'</td>

这是整个街区。

 $output .= '  
<form name="bulk_action_form" action="delete_multiple.php" method="post" onSubmit="return delete_confirm();"/>
      <div class="table-responsive">  
           <table class="table table-bordered">  
                <tr>  

                     <th width="10%">Id</th>  
                     <th width="40%">Name</th>  
                     <th width="40%">Email</th>  
                     <th width="40%">Address</th>  
                     <th width="10%">phoneNumber</th>  
                     <th width="10%">appointmentTime</th> 
                     <th width="10%">appointmentDate</th> 
                     <th width="50%">message</th> 
                     <th width="10%">delete</th>
                     <th><input type="checkbox" name="select_all" id="select_all" value=""/></th>
                </tr>';  



                             if(mysqli_num_rows($result) > 0)  
                             {  
                                  while($row = mysqli_fetch_array($result))  
                                  {  
                                       $output .= '  




                <tr>  

                     <td>'.$row["id"].'</td>
                     <td class="name" data-id1="'.$row["id"].'" contenteditable>'.$row["name"].'</td>  
                     <td class="email" data-id2="'.$row["id"].'" contenteditable>'.$row["email"].'</td>
                     <td class="address" data-id2="'.$row["id"].'" contenteditable>'.$row["address"].'</td>  
                     <td class="phoneNumber" data-id2="'.$row["id"].'" contenteditable>'.$row["phoneNumber"].'</td>  
                     <td class="appointmentTime" data-id2="'.$row["id"].'" contenteditable>'.$row["appointmentTime"].'</td>  
                     <td class="appointmentDate" data-id2="'.$row["id"].'" contenteditable>'.$row["appointmentDate"].'</td>
                     <td class="message" data-id2="'.$row["id"].'" contenteditable>'.$row["message"].'</td>
                     <td><button type="button" name="delete_btn" data-id3="'.$row["id"].'" class="btn btn-xs btn-danger                             btn_delete">Delete</button></td>
                     <td><input type="checkbox" name="'.checked_id[].'" class="checkbox" value="'.$row["id"].'"/></td>
                </tr>  
           ';  
      }                                   

 }  
 else  
 {  

      $output .= '<tr><td colspan="4">Data not Found</td></tr>';  
 }  


 $output .= '</table>  
      </div></form>';  
 echo $output;  
 ?>  

【问题讨论】:

    标签: php html mysql crud


    【解决方案1】:

    结构不正确:

    1. 缺少结束标签
    2. 缺少引号

    这样使用:

    <input type="checkbox" name="'.checked_id[].'" class="checkbox" value="'.$row["id"].'"/></td>
                                ^            ^ ^ ^                        ^              ^^^
    

    【讨论】:

    • 还是不行。另外,我已经尝试过了。我发布的只是我的争执之一。
    • 你去掉分号了吗?
    • 是的,我去掉了分号。
    • 我加了这个,好像显示了我的功能。但我不知道它是否是一个有效的结构。 checked_id [ ' ' ]
    • checked_id[] PHP 数组变量是什么,或者您想用该名称调用该控件?
    【解决方案2】:

    首先你必须将echoPHP 变量写入HTML,你不能只写它们的名字,因为HTML 不理解这一点。 这是您第一行中的示例,您在大多数代码中都给出了相同的示例。 你的代码:

    name='.checked_id[];.' class="checkbox" value='.$row["id"].
    

    应该如何:

    name='<?php echo checked_id[]; ?>' class="checkbox" value='<?php echo $row["id"]; ?>'
    

    另外,我认为checked_id[] 应该带有数组索引,不能留空。如果我错了,请纠正我,并在整个页面中使用此示例,因为要显示 PHP 变量,您必须打开 HTML 并在此处回显您的变量,例如 name="&lt;?php echo $somevariable; ?&gt;"

    试试这个:

    <?php
    $output .= "";
    ?>  
    <form name="bulk_action_form" action="delete_multiple.php" method="post" onSubmit="return delete_confirm();"/>
          <div class="table-responsive">  
               <table class="table table-bordered">  
                    <tr>  
    
                         <th width="10%">Id</th>  
                         <th width="40%">Name</th>  
                         <th width="40%">Email</th>  
                         <th width="40%">Address</th>  
                         <th width="10%">phoneNumber</th>  
                         <th width="10%">appointmentTime</th> 
                         <th width="10%">appointmentDate</th> 
                         <th width="50%">message</th> 
                         <th width="10%">delete</th>
                         <th><input type="checkbox" name="select_all" id="select_all" value=""/></th>
                    </tr>';  
                            <?php
    
    
                                 if(mysqli_num_rows($result) > 0)  
                                 {  
                                      while($row = mysqli_fetch_array($result))  
                                      {  
                                           $output .= '  
    
    
    
                            ?>
                    <tr>  
    
                         <td><?php echo $row["id"]; ?></td>
                         <td class="name" data-id1="<?php echo $row["id"]; ?>" contenteditable><?php echo $row["name"]; ?></td>  
                         <td class="email" data-id2="<?php echo $row["id"]; ?>" contenteditable><?php echo $row["email"]; ?></td>
                         <td class="address" data-id2="<?php echo $row["id"]; ?>" contenteditable><?php echo $row["address"]; ?></td>  
                         <td class="phoneNumber" data-id2="<?php echo $row["id"]; ?>" contenteditable><?php echo $row["phoneNumber"]; ?></td>  
                         <td class="appointmentTime" data-id2="<?php echo $row["id"]; ?>" contenteditable><?php echo $row["appointmentTime"]; ?></td>  
                         <td class="appointmentDate" data-id2="<?php echo $row["id"]; ?>" contenteditable><?php $row["appointmentDate"]; ?></td>
                         <td class="message" data-id2="<?php echo $row["id"]; ?>" contenteditable><?php echo $row["message"]; ?></td>
                         <td><button type="button" name="delete_btn" data-id3="<?php echo $row["id"]; ?>" class="btn btn-xs btn-danger                             btn_delete">Delete</button></td>
                         <td align="center"><input type="checkbox" name="<?php echo $checked_id[]; ?>" class="checkbox" value="<?php echo $row["id"]; ?>"</td>
                    </tr>  
    
          }  
    

    【讨论】:

    • 请原谅我没有放整个代码,但 echo 不是必需的 - 将它设置为那样。我会更新代码。只是数组不起作用。
    • 是的,因为你在 php 中做所有事情,但你应该将它们分开并使用 html 进行样式设置和 php 进行编码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 2010-10-12
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    相关资源
    最近更新 更多