簡體   English   中英

PHP / SQL語法:將變量傳遞給SQL查詢

[英]PHP/SQL syntax: passing variable to SQL query

我很累,想看看有什么不對勁。 我有兩個PHP。 從第一個我發送變量'select1'(基本上是id)到第二個,我想更新該記錄上傳pdf文件。

$id = "-1";
if (isset($_GET['select1'])) {
  $id = mysql_real_escape_string($_GET['select1']);
}



if(isset($_POST['Submit'])) {
    $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
    $my_upload->the_file = $_FILES['upload']['name'];
    $my_upload->http_error = $_FILES['upload']['error'];
    if ($my_upload->upload()) { // new name is an additional filename information, use this to rename the uploaded file
        mysql_query(sprintf("UPDATE sarcini1 SET file_name = '%s' WHERE id_sarcina = '%s'", $my_upload->file_copy, $id));
    }
}

如果我添加一個有效ID的行,例如:

$id = 14;

這是工作。 我做錯了什么? 謝謝!

您同時使用GET和POST。 據我所知,這個條件並沒有返回True

if (isset($_GET['select1']))

編輯:如果您在上面沒有找到任何答案; 也許更多的信息/代碼可以幫助找到解決方案。

如果你需要接受post和get,那么你應該嘗試類似下面的代碼來檢索變量。

$var = 'select1';
if( isset( $_POST[$var] ) ) {
    $id = $_POST[$var];
} else if( isset( $_GET[$var] ) ) {
    $id = $_GET[$var];
} else {
    $id = -1;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM