Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么单击按钮时传递了错误的值_Php_Html_Mysql - Fatal编程技术网

Php 为什么单击按钮时传递了错误的值

Php 为什么单击按钮时传递了错误的值,php,html,mysql,Php,Html,Mysql,好的,我正在尝试从SQL数据库获取内容,以便在按下按钮时填充字段。问题是,无论按下哪个按钮,它总是将最后一行的值发送到php。我是一个php/mySQL noob。我很抱歉,如果之前有人问过/回答过,我已经在网站上搜索了几个小时,没有发现任何帮助我找到答案的东西 索引页图像和代码: AMS 物品清单 出版日期 标题 行动 几乎可以肯定,这条线路存在问题: $recid=过滤器输入(输入后,“recid”) 我建议您执行var_dump($\u POST)并查看POST数据中的内容。我认为您应该

好的,我正在尝试从SQL数据库获取内容,以便在按下按钮时填充字段。问题是,无论按下哪个按钮,它总是将最后一行的值发送到php。我是一个php/mySQL noob。我很抱歉,如果之前有人问过/回答过,我已经在网站上搜索了几个小时,没有发现任何帮助我找到答案的东西

索引页图像和代码:


AMS
物品清单
出版日期
标题
行动

几乎可以肯定,这条线路存在问题:

$recid=过滤器输入(输入后,“recid”)


我建议您执行var_dump($\u POST)并查看POST数据中的内容。

我认为您应该尝试关闭循环中的表单标记。您需要进行更多调试,我需要更多信息以便能够帮助您。执行“echo$recid;”和“print\r($title);所以我们可以看到变量的内容。是的,那是丢失的表单结束标记。伙计,现在我觉得自己像个傻瓜,我已经盯着这个代码看了好几个小时了。谢谢斯梅尼!
<?php
require_once('database.php');

$query = 'SELECT * FROM omniarticles 
     ORDER BY recid';

$statement1 = $db->prepare($query);
$statement1->execute();
$article = $statement1->fetchAll();
$statement1->closeCursor();
?>
<!DOCTYPE HTML>
<html>
<head>
    <title>AMS</title>
    <link rel="stylesheet" type="text/css" href="basic.css">
</head>
<body>
    <h3>Article List</h3>
    <table>
        <tr>
        <th>Publication Date</th>
        <th>Title</th>
        <th>Action</th>
        </tr>

        <?php foreach ($article as $articles) : ?>
                <tr>
                    <td><?php echo $articles['publicationDate']; ?></td>
                    <td><?php echo $articles['title']; ?></td>
                    <td><form action="view.php" method="post">
                            <input type="hidden" name="recid" 
                                   value="<?php echo $articles['recid'];?>">
                            <input type="submit" value="View">
                        <input type="submit" value="Edit">
                    </td>
                </tr>
        <?php endforeach; ?>
    </table>
</body>
</html>
<?php
$recid = filter_input(INPUT_POST, 'recid');

require_once('database.php');

$q = 'SELECT * FROM omniarticles
    WHERE recid = :recid';
$s = $db->prepare($q);
$s->bindValue(':recid', $recid);
$s->execute();
$title = $s->fetch();
$s->closeCursor();

?>

<!DOCTYPE HTML>
<html>
<head>
    <title>AMS</title>
    <link rel="stylesheet" type="text/css" href="Module5Lab.css">
</head>
<body>
        <label>Article Title</label>
        <input type="text" name="article_title" value="<?php echo $title['recid']; ?>"/>
        <br/>
        <br/>
        <label>Article Summary</label>
        <textarea rows="4" cols="50"></textarea>
        <br/>
        <label>Article Content</label>
        <textarea rows="20" cols="50"><?php echo $title['content']; ?></textarea>
        <br/>
        <label>Publication Date</label>
        <input type="text" name="publication_date"/>
        <br/>
</body>
</html>