-1

这是我的 php 代码。

<?php
session_start();
foreach($_POST AS $key => $val) {
$_SESSION[$key]=$val;
}

mysql_connect('localhost', 'bikec_user', '4348@TxState');
mysql_select_db('bikecats_database');

$cnetid=$_POST['cnetid'];
$cpassword=$_POST['cpassword'];


$cnetid = stripslashes($cnetid);
$cpassword = stripslashes($cpassword);
$cnetid = mysql_real_escape_string($cnetid);
$cpassword = mysql_real_escape_string($cpassword);

$sql="SELECT RentalID, BikeID, RentalStartDate, RentalEndDate
  FROM rental  
  WHERE CustTxStateNetID = '$cnetid'";
$result=mysql_query($sql) OR die(mysql_error());
$row=mysql_fetch_assoc($result);

$rentalid=$row['RentalID'];
$bikeid=$row['BikeID'];
?>

这是html代码。它应该显示从数据库中检索到的查询,但由于某种原因,当我运行它时,表出现空白。我知道我只是在呼应两个变量,但即使这些变量也是空的。

        <div class="span9">  
          <h2>My Account</h2>
          <p><strong>My Rentals</strong></p>
        <table class="table table-striped">  
            <thead>  
              <tr>  
                <th>Rental ID</th>   
                <th>Bike ID  
                <th>Check-Out Date</th>  
                <th>Return Date</th>  
              </tr>  
            </thead>  
            <tbody>  
              <tr>  
                <td><?php echo $rentalid ?></td>    
                <td><?php echo $bikeid ?></td>   
                <td></td> 
                <td></td>  
              </tr>   
              <tr>  
                <td></td>  
                <td></td>   
                <td></td>   
                <td></td>  
              </tr>
            </tbody> 
        </table><br>
        </div><!-- end span -->
4

1 回答 1

0

尝试这个:

---------------------------------------已编辑---------- ------------------

<?php
   session_start();



  if(isset($_POST['cnetid'])){
  mysql_connect('localhost', 'bikec_user', '4348@TxState');
  mysql_select_db('bikecats_database');  
  $cnetid = mysql_real_escape_string($_POST['cnetid']);
  $cpassword = mysql_real_escape_string($_POST['cpassword']);
  $table = "<table class='table table-striped' >  
              <thead>  
                <tr>  
                  <th>Rental ID</th>   
                  <th>Bike ID  
                  <th>Check-Out Date</th>  
                  <th>Return Date</th>  
                </tr>  
              </thead>  
              <tbody>  
              ";
  $sql="SELECT RentalID, BikeID, RentalStartDate, RentalEndDate
    FROM rental  
    WHERE CustTxStateNetID = '$cnetid'";
    $body = "";
  $result=mysql_query($sql) OR die(mysql_error());
   while ($row=mysql_fetch_assoc($result))
   {
     $body = $body." <tr><td>".$row['RentalID']."</td>  
                     <td>".$row['BikeID']."</td>   
                     <td>".$row['RentalStartDate']."</td> 
                     <td>".$row['RentalEndDate']."</td></tr> ";
   }
   $table = $table.$body."   
                <tr>  
                  <td></td>  
                  <td></td>   
                  <td></td>   
                  <td></td>  
                </tr>
              </tbody> 
          </table>" ;

  }
  else
  {
    $table = "No data..";
  }

  ?>


  <div class="span9">  
        <h2>My Account</h2>
        <p><strong>My Rentals</strong></p>
        <?php echo $table; ?>
        <br>
  </div>

PS:发现错误,更正,并测试代码 xD

萨卢多斯 ;)

于 2013-03-21T01:15:39.697 回答