[英]PHP/SQL syntax: passing variable to SQL query
I am getting tired trying to see what is wrong. 我很累,想看看有什么不对劲。 I have two php.
我有两个PHP。 From the first I am sending a variable 'select1' (basically the id) to the second and than I want to update that record uploading a pdf file.
从第一个我发送变量'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));
}
}
If I put a line with a valid id, like: 如果我添加一个有效ID的行,例如:
$id = 14;
it is working. 这是工作。 What I am doing wrong?
我做错了什么? Thank you!
谢谢!
You are using both GET and POST at the same time. 您同时使用GET和POST。 As far as I can see, this condition is not returning True
据我所知,这个条件并没有返回True
if (isset($_GET['select1']))
Edit: If you don't find any answer in above; 编辑:如果您在上面没有找到任何答案; maybe some more information/code can help getting to a solution.
也许更多的信息/代码可以帮助找到解决方案。
If you need to accept both post & get, then you should try something like the code below to retrieve the variable. 如果你需要接受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.