[英]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.