Combine $_GET and $_POST in PHP?

血红的双手。 提交于 2019-12-14 03:24:42

问题


for some friends and family (different sites), I created a script that allows them to input data into the database. With

echo ("<a href=\"./pagina.php?ID=" . $row['ID'] . "\">" . $row['ID'] . "<br>");

, I 'send' the ID of the requested table to the URL.

In pagina.php, I have this code:

ID: <?php echo $_GET["ID"]; ?>

That works, of course, but now I want to use that ID to also display the data from the database, so not from the URL. These values are " . $row['onderwerp'] . " and " . $row['tekst'] . " (There may be more values to come, but I'm just a beginner, trying to get something to work).

I know this is possible, but I just can't get anything to work, as I have just started learning PHP.

I hope you can help me.


回答1:


$id = (int)$_GET['id'];

$sql = "SELECT onderwerp, tekst FROM yourtable WHERE id=$id";
$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($result)) {
    echo "{$row['onderwerp']} - {$row['tekst']}<br />";
}



回答2:


If you don't care whether data came from a $_COOKIE, $_GET, or $_POST, you can use $_REQUEST.



来源:https://stackoverflow.com/questions/5809616/combine-get-and-post-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!