在PDO中使用$ _GET方法

时间:2014-07-12 10:11:37

标签: php mysql pdo

我试图从mySql数据库中的表中获取用户详细信息,这就是我所拥有的;

admin.php的

<?php
$search = $_POST['search'];

$q = "SELECT * FROM quotes WHERE
          firstname LIKE '%$search%' OR 
          lastname LIKE '%$search%' OR 
          email LIKE '%$search%' OR 
          phone LIKE '%$search%' OR
          company_name LIKE '%$search%' OR
          ticker LIKE '%$search%' OR
          shares_held LIKE '%$search%' OR
          shares_sell LIKE '%$search%' OR
          date LIKE '%$search%' OR
          time LIKE '%$search%' OR
          ref LIKE '%$search%' OR
          agent LIKE '%$search%' OR
          ip LIKE '%$search%' OR
          ip_value LIKE '%$search%' OR
          domain LIKE '%$search%' OR
          tracking_page_name LIKE '%$search%'
          ";

$query = $db->prepare($q);

$query->bindValue(1, "%$search%", PDO::PARAM_STR);

$query->execute();
if (!$query->rowCount() == 0) {
    while ($results = $query->fetch()) {

        $str_name = $results['quotes_id'];
        $str_link = "<a href = 'client.data.php?id=" . $results['quotes_id'] . "'>SMWS-089" . $str_name . "</a>";
        ?>

        <tr>
        <td><?php echo date("M d, Y", strtotime($results['date'])) ?>  <?php echo $results['time'] ?></td>
        <td><?php echo $str_link ?></td>
        <td><?php echo $results['firstname'] ?> <?php echo $results['lastname'] ?></td>
        <td><?php echo $results['email'] ?></td>
        <td><?php echo $results['phone'] ?></td>
        <td><?php echo $results['company_name'] ?></td>
        <td><?php echo $results['ticker'] ?></td>
        <td><?php echo $results['shares_held'] ?></td>
        <td><?php echo $results['shares_sell'] ?></td>
        <!--<td><?php echo $results['ref'] ?></td>
        <td><?php echo $results['agent'] ?></td>
        <td><?php echo long2ip($results['ip']) ?></td>
        <td><?php echo $results['ip_value'] ?></td>
        <td><?php echo $results['tracking_page_name'] ?></td>-->
        </tr>
        <?php
    }
} else {
    echo '<strong>Sorry, No Results Found</strong><br><br>';
}
?>

client.data.php

<table width="40%" border="0" cellspacing="0" cellpadding="0">
     <tr>
     <th scope="col">Client Data</th>
     </tr>
     <?php
     require_once '../includes/db.php';

$query = $db->prepare('SELECT * FROM quotes WHERE quotes_id = :quotes_id');

$query->bindParam(':quotes_id', $_GET['quotes_id'], PDO::PARAM_INT);

$query->execute();

if($query->rowCount()) {
    $data = $query->fetchAll();
    while ($results = $data) {
        ?>
        <tr>
        <td><?php echo date("M d, Y", strtotime($results['date'])) ?>  <?php echo $results['time'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['firstname'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['lastname'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['email'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['phone'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['company_name'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['ticker'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['shares_held'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['shares_sell'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['ref'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['agent'] ?></td>
        </tr>
        <tr>
        <td><?php echo long2ip($results['ip']) ?></td>
        </tr>
        <tr>
        <td><?php echo $results['ip_value'] ?></td>
        </tr>
        <tr>
        <td><?php echo $results['tracking_page_name'] ?></td>
        </tr><br><br>
        <?php 
    }
}

?>
</table>

这一切都运行正常,但是当我从admin.php上点击特定的id时,它根本没有数据,没有错误,没有任何错误。我的$ _GET方法的bindParam是否正确???

$query->bindParam(':quotes_id', $_GET['quotes_id'], PDO::PARAM_INT);

0 个答案:

没有答案