错误:SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'rowid'

时间:2018-01-23 08:03:25

标签: php html mysql href

我正在尝试通过ID传递href。即使我以前做了很多次,它仍然给我这个奇怪的错误。错误是:

  

错误:SQLSTATE [42S22]:找不到列:1054未知列'rowid'   在'where子句'

这是我用于href中的id的行:

<?php
    $link = mysql_connect("localhost", "root", "");
    mysql_select_db("meubelfabriek");
    $result = mysql_query("SELECT * FROM inbox") or 
    die(mysql_error());

    while($rowz = mysql_fetch_array($result)) {
        $id = $rowz['id'];

?>
<td>
<li class="list-group-item text-right"><a class="pull-left" href="login/email.php?id=rowid=<?= $rowz['id'] ?>">  <?php echo '<h7>' . $rowz['email'] . '</a> 2.13.2014</li>
</td>

email.php

<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th></tr>";

class TableRows extends RecursiveIteratorIterator {
    function __construct($it) {
        parent::__construct($it, self::LEAVES_ONLY);
    }

    function current() {
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }

    function beginChildren() {
        echo "<tr>";
    }

    function endChildren() {
        echo "</tr>" . "\n";
    }
}


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "meubelfabriek";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $id = $_GET['id'];

    $stmt = $conn->prepare("SELECT id, voornaam, achternaam, email, nummer, bericht FROM inbox WHERE id = $id");
    $stmt->execute();



    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
        echo $v;
    }
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>

在我的数据库中,ID仅由ID定义。所有准备声明都是正确的。有谁知道为什么我不能让这个工作?在过去它似乎工作得很好。无论如何,我希望有人能帮助我。

2 个答案:

答案 0 :(得分:2)

我认为这一行是错误的。

<li class="list-group-item text-right"><a class="pull-left" href="login/email.php?id=rowid=<?= $rowz['id'] ?>">  <?php echo '<h7>' . $rowz['email'] . '</a> 2.13.2014</li>

请更改href

login/email.php?id=rowid=<?= $rowz['id'] ?>

login/email.php?id=<?= $rowz['id'] ?>

答案 1 :(得分:0)

 <li class="list-group-item text-right"><a class="pull-left" href="login/email.php?id=<?= $rowz['id'] ?>">  <?php echo '<h7>' . $rowz['email'] . '</a> 2.13.2014</li>

将此行替换为您的代码。您已撰写rowid而非$rowz['id']