嗨,我一直在好奇如何獲得在像url的pid = 4的URL中的id,並在sql中的更新語句中使用它。那麼繼承人我的代碼,但不能得到它的工作原因是未定義的變量ID,其中的值是在URL中。從網址獲取ID; PHP,MySQL
我function.php
function update_spot(){
$id=$_GET[pid];
if (isset($_POST['update'])){
$sql="UPDATE reports SET date_time_started='$_POST[date1]' ,
date_time_finished= '$_POST[date2]',
barangay='$_POST[brgy]',
street= '$_POST[street]',
owner='$_POST[owner]',
cause='$_POST[cause]',
motive='$_POST[motive]',
firfighter='$_POST[firefighter]'.
civilian='$_POST[civilian]',
ifirefighter='$_POST[ifirefighter]',
icivilian='$_POST[icivilian]',
occupancy='$_POST[occupancy]',
ed='$_POST[ed]',
alarm='$_POST[alarm]'
where id='".$id."' ";
if (!mysql_query($sql)){ die('Error: ' . mysql_error()); } ?>
<script type='text/javascript'>alert('sucessful changed try it next time you log
in.');window.location='view_inbox.php';</script> <?php
}
}
似乎我不能在URL獲得ID。我的網址顯示是這樣的形式PHP?PID = 5
注意,代碼非常容易受到SQL注入 –
你有一個'.'而不是','的'後「$ _ POST [消防隊員]」' – Phil
你應該使用'mysqli'或'PDO'庫現在,而不是'mysql'。確保你清理你的輸入,否則你基本上是讓人們免費統治你的數據庫。 – vimist