我有一个来自上一页的值,现在使用该值运行 mysql_query:
$sql = "SELECT $value1, $value2 from table where some_value = $previous_page
$result = mysql_query($sql) or die
$row = mysql_fetch_array($result);
echo $row[$value1, $value2];
在 HTML 文件中,我有一个输入框,但当用户看到它时,我想先用 $value1 填充此框。 我怎样才能实现这个目标?
(我可以像上面那样回显多个值吗?)
最佳答案
确保检查值是否确实存在,以防止错误!
我会连续运行 PHP 检查,例如:
<?php $name = ($value1 != null) ? $value1 : null; ?>
// This checks if it exists, and either returns the value or nothing if it doesn't exist.
然后在 HTML 中,我将拥有一个表单(可以是新表单,也可以是相同表单):
<input type="text" name="value1" value="<?php echo $name; ?>" />
<!-- This allows it to either place value in the text box, or does nothing if it doesn't exist. -->
我给了你代码,假设你知道如何将它定向到表单等等。我尝试尽可能跳过语义。
关于php - 使用 php 从上一页获取值以显示在当前页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33195156/