从上一页获取ID。

时间:2016-02-20 17:19:12

标签: php mysql

我试图从index.php获取id以通过doLandingPage.php传递给doAttendance.php。但是因为它不是一个表格而没有看到获取doAttendance.php的id。

  

注意:未定义索引:C:\ xampp \ htdocs \ junhao \ doAttendance.php中的id   在第5行

     

警告:mysql_query()要求参数1为字符串,资源   在第9行的C:\ xampp \ htdocs \ junhao \ doAttendance.php中给出   未知的系统变量'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 个答案:

答案 0 :(得分:0)

修改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>";
     }

?>