dryb38654 2019-05-11 14:45
浏览 78

PHPMYADMIN中的数据在PHP页面中实现为HTML表单,通过PHP POST发送

I have data in my PHPMYADMIN in a few columns and rows.

Via PHP I read the Data out of my SQL Table and print it into a table.

The last of my table is a action button. So the whole table is a echo and within the table there's a html form in the last , but only with a submit button (input type="hidden") but the value should be the "id" out of my SQL table.

Here's the problem. How can I get the id of one row into the value of an input field? . $row["id"]. doesn't work. How can I fix this problem?

This is for a Website where the user can vote a table row up and then with the html form it is sending via http post to another page where it overrides the current number in the database with +1

$sql = "SELECT * FROM votingpoll ORDER BY votecount DESC";
$result = $conn->query($sql);

echo "$id";

echo "<table>";
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr>
                <td> 
                    <form action='vote.php' method='post'>
                        <input type='text' name='id' value='$id'> 
                        <input type='submit' value='VOTE'> 
                    </form>
                </td>
            </tr>";
    }
} else {
    echo "0 results";
}

Thank you!!!

  • 写回答

2条回答 默认 最新

  • dongleman4760 2019-05-11 14:59
    关注

    You can do $row[id] i.e. leave the quotes off when the array reference is used inside a double quoted string.

    $sql = "SELECT * FROM votingpoll ORDER BY votecount DESC";
    $result = $conn->query($sql);
    
    // remove this it does not appear to do anything useful here
    //echo "$id";
    
    echo "<table>";
    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            echo "<tr>
                    <td> 
                        <form action='vote.php' method='post'>
                            <input type='text' name='id' value='$row[id]'> 
                            <input type='submit' value='VOTE'> 
                        </form>
                    </td>
                </tr>";
        }
    } else {
        echo "0 results";
    }
    

    Or if you prefer you could use

    <input type='text' name='id' value='{$row['id']}'> 
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度