douan3019 2016-12-29 19:12
浏览 87
已采纳

单独的PHP和HTML

I have been trying to clean up the readability of my code and based off a number of answers from here, I have gotten pretty far, however I cannot get my code to work when I try split the HTML from the PHP. The code worked fine when I used the echo statement within PHP code block.I'm trying to output the result of a stored proc to an HTML table outside of PHP block, but still using PHP variables here is my code:

<?php
include_once ('includes/admin.php');
if (isset($_GET['submit'])) {
    $id = $_GET['val1'];
}
$wResult = mysqli_query($con, "call getwisherid($id)");
?>

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link href="sqlcss.css" type="text/css" rel="stylesheet">
    </head>
    <body>
        <form>
            <input type="text" name="val1" value="" />
            <input type="submit" value="submit" name="submit" />
        </form>

      <?php while($row = mysqli_fetch_array($wResult)){ ?>

<div class="wish_result">
  <table>
    <tr>
      <td><?php echo $row['name'];?></td>
     <td><?php echo $row['password'];?></td>
    </tr>
  </table>
</div>
    </body>
</html>
  • 写回答

2条回答 默认 最新

  • doulu5717 2016-12-29 19:40
    关注

    Some enhancement in your code (along with error reporting and query);-

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors',1);
    ?>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <link href="sqlcss.css" type="text/css" rel="stylesheet">
        </head>
        <body>
            <form>
                <input type="text" name="val1" value="" />
                <input type="submit" value="submit" name="submit" />
            </form>
            <?php
                include_once ('includes/admin.php');
                if (isset($_GET['val1']) && !empty($_GET['val1'])) {
                    $id = $_GET['val1'];
                    if($con){
                        $wResult = mysqli_query($con, "SELECT name,password FROM <table name> WHERE id = $id");  // put here the appropriate table name
                        // i don't know what is this :- call getwisherid($id) and it is correct or not 
                        if($wResult){
                            if(mysqli_num_rows($wResult)>0){
            ?>
                <div class="wish_result">
                    <table>
                        <?php while($row = mysqli_fetch_assoc($wResult)){ ?>
                        <tr>
                            <td><?php echo $row['name'];?></td>
                            <td><?php echo $row['password'];?></td>
                        </tr>
                        <?php }?>
                    <?php }else{echo "<tr>No Record Available.</t>";}?>
                </table>
                <?php }else{"Query error".mysqli_error($con);}?>
            </div>
            <?php }else{echo "connection error".mysqli_connect_error();}?>
        </body>
        <?php }else{echo "please fill the form value;"}?>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号