[英]How do I use a user's input as 1 of the arguments for an sql function?
*這是代碼的簡化版本
我有一個查詢
SELECT func('123', x, '789');
X取決於用戶在文本框中的輸入;
我試過了
$result = pg_query($conn, "SELECT func('123', _GET['x'], '789')");
從哪里檢索x
<form method="get">
x: <input type="text" name="x"><br/>
<input type="submit">
</form>
但是,這似乎不起作用。 另外,PHP在html中的位置是否有所不同?
這是完整的代碼:
<!DOCTYPE html>
<html>
<body>
<?php
$string_connection = "host=localhost port=5432 user=myname dbname=mydb";
$conn = pg_connect($string_connection);
$result = pg_query($conn, "SELECT get_champ('123', $_GET['x'], '789')");
while ($row = pg_fetch_row($result)) {
echo "$row[0]";
echo "<br/>\n";
}
?>
<form method="get">
End Date: <input type="text" name="x"><br/>
<input type="submit">
</form>
</body>
</html>
采用:
$x = $_GET['x'];
然后使用($conn, "SELECT get_champ('123', '$x', '789')")
$string_connection = "host=localhost port=5432 user=myname dbname=mydb";
$conn = pg_connect($string_connection);
$x = $_GET['x'];
$result = pg_query($conn, "SELECT get_champ('123', '$x', '789')");
while ($row = pg_fetch_row($result)) {
echo "$row[0]";
echo "<br/>\n";
}
如果是int
,則使用$x = (int)$_GET['x'];
name"x"
丟失=
更改為name="x"
另外,請使用$_GET['x']
或{$_GET['x']}
$result = pg_query($conn, "SELECT func('123',{$_GET['x']}, '789')");
和
<form method="get">
x: <input type="text" name="x"><br/>
<input type="submit">
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.