dongxun4110 2016-06-02 22:34 采纳率: 0%
浏览 53

从多个表中读取数据

Read data from multiple tables.... . Can anyone figure out why this code won't work... . When I make checkbox selection, the alert (script) is showing up, . I known there should be come a result of data. . Manny thanks, Benny

<?php
 include_once 'dbcon.php';
 if(isset($_POST['chk'])=="")
 {
  ?>
    <script>
  alert('Er moet tenminste één checkbox geselecteerd zijn !!!');
  window.location.href='../EVENT/eventIndex.php';
  </script>
<?php
 }
 $chk = $_POST['chk'];
 $chkcount = count($chk);
?>    
<form method="post" name="frm">
<table width="90%" align="center" border="0">
    <tr>
        <td colspan="6"><a href="NewTicket.php" class="StyleTxt">Voeg een nieuw ticket toe...<br>
        </a></td>
    </tr>
    <tr>
        <th width="15%" class="StyleTxt">Naam</th>
        <th width="15%" class="StyleTxt">Voornaam</th>
        <th width="15%" class="StyleTxt">Partner achternaam</th>
        <th width="15%" class="StyleTxt">Partner voornaam</th>
        <th width="15%" class="StyleTxt">Herbalife-ID</th>
        <th width="15%" class="StyleTxt">Upline</th>
    </tr>
<?php  
for($i=0; $i<$chkcount; $i++)
{
$id = $chk[$i];

$res=$MySQLiconn->query("SELECT user.FName, user.LName, user.HerbalifeID, user.UplineS, registratie.PartnerFName, registratie.PartnerLName, registratie.NaamVIP1, registratie.NaamVIP2, registratie.NaamVIP3, registratie.NaamVIP4, registratie.NaamVIP5, registratie.NaamVIP6, registratie.NaamVIP7, registratie.NaamVIP8, registratie.NaamVIP9, registratie.NaamVIP10, registratie.NaamVIP11, registratie.NaamVIP12 FROM registratie INNER JOIN user ON registratie.userID = user.UserID AND registratie.eventID=".$id);

 while($row=$res->fetch_array())
 {
?>
   <tr>
<td style="background-color:gold;"><?php echo $row['FName'];?></td>
<td style="background-color:gold;"><?php echo $row['LName'];?></td>
<td style="background-color:gold;"><?php echo $row['PartnerFName'];?></td>
<td style="background-color:gold;"><?php echo $row['PartnerLName'];?></td>
<td style="background-color:gold;"><?php echo $row['HerbalifeID'];?></td>
<td style="background-color:gold;"><?php echo $row['UplineS'];?></td><br />
</tr>
<tr>
<td>VIP: <?php echo $row['NaamVIP1'];?></td>
<td>VIP: <?php echo $row['NaamVIP2'];?></td>
<td>VIP: <?php echo $row['NaamVIP3'];?></td>
<td>VIP: <?php echo $row['NaamVIP4'];?></td>
<td>VIP: <?php echo $row['NaamVIP5'];?></td>
<td>VIP: <?php echo $row['NaamVIP6'];?></td>
</tr>
<tr>    
<td>VIP: <?php echo $row['NaamVIP7'];?></td>
<td>VIP: <?php echo $row['NaamVIP8'];?></td>    
<td>VIP: <?php echo $row['NaamVIP9'];?></td>
<td>VIP: <?php echo $row['NaamVIP10'];?></td> 
<td>VIP: <?php echo $row['NaamVIP11'];?></td>
<td>VIP: <?php echo $row['NaamVIP12'];?></td> 
   </tr> 
<?php
  } 
 }
?>
  • 写回答

1条回答 默认 最新

  • dqnrk44682 2016-06-02 23:28
    关注

    Aside from the SQL injection vulnerabilities in your code which I encourage you to read up on (see http://php.net/manual/en/security.database.sql-injection.php) there is a small issue on your code.

    if(isset($_POST['chk'])=="")
    

    That is not correct, because isset returns a boolean and you cannot compare boolean to string, it is invalid. Check Mike's comment below. If you wanted to check for the string not being empty and set, do:

    if(isset($_POST['chk']) && !empty($_POST['chk']))
    

    The manpage for isset is here: http://php.net/manual/en/function.isset.php; "Returns TRUE if var exists and has value other than NULL, FALSE otherwise."

    Another small thing: $chk does not default to a value, which means, if it is not provided, the whole script will blow up. To fix this, you can add a default value, using the new syntax in PHP7 but for compatibility:

    if (!isset($_POST['chk']) {
        $chk = 'something'
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题