douzizang7783 2016-02-20 17:19
浏览 35
已采纳

从上一页获取ID。

I am trying to get the id from the index.php to pass through doLandingPage.php to doAttendance.php. but doesn't seeem to get the id to doAttendance.php since it is not a form.

Notice: Undefined index: id in C:\xampp\htdocs\junhao\doAttendance.php on line 5

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\junhao\doAttendance.php on line 9 Unknown system variable 'name'

index.php

<div class="row" style="position:absolute; left:35%;top:40%;">
    <form method="post" action="doLandingPage.php">
              <div class="search row">
                <div class="small-12 columns">
                  <input  name="search" type="text" placeholder="Enter your name..">
                </div>
                <div class="small-12 columns">
                <center>
                  <input type="submit" name="Submit" value="Submit" class="button round">
                </center>
            </div>
        </div>
    </form>
</div>

doLandingPage.php

<body id="page-2">
<div class="container">
<nav>
<ul>
  <li><a href=""></a></li>

</ul>
<div class="overlay-button ">
  <a class="btn-open" href="#"></a>
</div>
</nav>
<div class="overlay">
  <div class="wrap">
    <ul class="wrap-nav">
      <li><a href="#">Menu</a>
      <ul>
        <li><a href="http://localhost:8080/file/index.php">Home</a></li>
        <li><a href="http://localhost:8080/file/guests.php">Guest List</a></li>
      </ul>
      </li>
    </ul>
  </div>
</div>
<div class="row" style="position:absolute; left:35%;top:40%;">
  <form method="post" action="doLandingPage.php">
      <div class="row">
        <div class="large-12 columns">
          <div class="row">
            <center>
                    <?php 

         if(mysql_num_rows($query) > 0){

            while($row = mysql_fetch_array($query))
               {
                $id = $row['id'];
                $name = $row['name'];
                $table = $row['table'];

                echo "<h1>$name</h1>";
                echo "<h2>$table</h2>";
                echo "<a href='http://localhost:8080/file/index.php' class='button'>BACK</a>";
                echo "<a href='http://localhost:8080/file/doAttendance.php?id=<?php echo $row['id'];?>' class='button'>I'M HERE!</a>";

                }
              } else {
                echo "<h1>Name not found.</h1><br>";
        }

    ?>





          </center>
            </div>
          </div>
        </div>
      </div>
  </form>
</div>
</div>
</body>

doAttendance.php

<?php 
include "dbFunctions.php";

extract($_POST);
$id = $_REQUEST['id'];
$presence = 'Yes';

$selectQuery = "SELECT * FROM guests WHERE id = '$id'";
$selected = mysql_query($connect, $selectQuery) or die(mysql_error($connect));

if (mysql_num_rows($selected) > 0) {   
} else {
    $sql = "UPDATE guests SET presence='$presence' WHERE id = '$id' ";
    $updated = mysql_query($connect, $sql) or die(mysql_error($connect));
}
?>
  • 写回答

1条回答 默认 最新

  • dskzap8756 2016-02-20 18:01
    关注

    Modify some of your code in doLandingPage.php

    <?php
         if(mysql_num_rows($query) > 0){
             while($row = mysql_fetch_array($query))
             {
                  $id = $row['id'];
                  $name = $row['name'];
                  $table = $row['table'];
    
                  echo "<h1>$name</h1>";
                  echo "<h2>$table</h2>";
                  echo "<a href='http://localhost:8080/file/index.php' class='button'>BACK</a>";
    
                  //modified code 
                  echo "<a href='http://localhost:8080/file/doAttendance.php?id=". $row['id']. "' class='button'>I'M HERE!</a>";
    
             }//end of while
         } else {
                echo "<h1>Name not found.</h1><br>";
         }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么