在页面加载mysql查询:
$today = date('D, d M, Y');
$sql = "SELECT * FROM programs WHERE singleday = '$today' AND city = 'New York'";
我有一个日历,同时更改我想要根据日期选择数据和显示的日期:
<form method="post">
<input align="center" type="text" id="picker"
onchange="this.form.submit()" name="picker" size="30"/>
</form>
和
$sql = "SELECT * FROM programs
WHERE singleday = '$_POST[picker]' AND city = 'New York'";
所以我需要的是,去纽约时想要显示今天的数据,同时在同一页面上更改特定日期的日历日期显示数据。
请帮忙
答案 0 :(得分:0)
我看到3个明显的选择:
答案 1 :(得分:0)
你不能总是得到你想要的东西[...]但有时你会得到你需要的东西--Mick Jagger
请参阅:How does the SQL injection from the "Bobby Tables" XKCD comic work?
有关SQL注入的说明。
您在以下代码中有一个SQL注入漏洞
$sql = "SELECT * FROM programs
WHERE singleday = '$_POST[picker]' AND city = 'New York'";
将其更改为:
$mydate = mysql_real_escape_string($_POST[picker]);
$sql = "SELECT * FROM programs
WHERE singleday = '$mydate' AND city = 'New York'";
// ^ ^ these quotes must be there to be protected.