PHP没有显示任何值,但值肯定被传递

A user chooses a value from a select box which is then passed via a form to another page which should show the mysql record of that selection. This is not showing any results, however the value is definitely being passed as it can be echoed out.

<?php
    include("top.php");

    $db = getConnection();

    $eventID = $_POST['eventID'];

    echo $eventID;
    $queryEvent = $db->query("SELECT * FROM projectEvent WHERE eventID = '$eventID'");
    $queryEvent->setFetchMode(PDO::FETCH_ASSOC);
    $record = $queryEvent->fetchALL();
?>
<form name="form1" id="form1" method="post" action="deleteOpen.php">
<p> are you sure you want to delete the following Open Day? </p>
    <table width="200" cellpadding="0" cellspacing="0">
                <tr>
                <th scope="row">eventID</th>
                <td><?php echo $record -> eventID; ?></td>
                </tr>
                <tr>    
                <th scope="row">propertyID</th>
                <td><?php echo $record -> propertyID; ?></td>
                </tr>
                <tr>
                <th scope="row">eventDate</th>
                <td><?php echo $record -> eventDate; ?></td>
                </tr>
                <tr>
                <th scope="row">eventTime</th>
                <td><?php echo $record -> eventTime; ?></td>
                </tr>
                <tr>
                <th scope="row">eventDescription</th>
                <td><?php echo $record -> eventDescription; ?></td>
                </tr>
    </table>

Can anyone suggest why the values are not shown in the table?

Thanks

  1. to show data you shouldn't use POST method but GET instead.
  2. either escape your values with PDO::quote or use prepared statements with prepare/execute instead of query()
  3. if you are using ASSOC mode - why you are accessing them as a object properties?
  4. Moreover, you actually have a nested array, but accessing it as a single object. if you don't need an array - don't use fetchAll() then
  5. ALWAYS have error_reporting(E_ALL); in your scripts to see these silly mistakes.

Normally I do a little bit different of a method. It may not point out the problem but I think it will solve it. I usually dont use variables inside of quotes, but try below.

$sql = sprintf("SELECT * FROM projectEvent WHERE eventID = '%s'", $eventID);
$queryEvent = $db->query($sql);

You can concatenate the variable separately like this :

$queryEvent = $db->query("SELECT * FROM projectEvent WHERE eventID = ".$eventID.")";