这是我的php代码。如何从数据库检索信息并在表格中显示?
<?php
session_start();
foreach($_POST AS $key => $val) {
$_SESSION[$key]=$val;
}
mysql_connect('localhost', 'bikec_user', '[email protected]');
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 -->
使用[tag:PDO]进行连接。 'mysql_ *'已被弃用。 – hjpotter92 2013-03-21 01:02:41
尝试var_dump($ row)查看它返回的内容..也使用PDO – 2013-03-21 01:03:19
您需要确认sql是否首先返回结果。 – Jesse 2013-03-27 23:20:14