0

I am getting tired trying to see what is wrong. I have two 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.

$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 = 14;

it is working. What I am doing wrong? Thank you!

1
  • what's the error that you got? Commented Sep 14, 2012 at 7:00

2 Answers 2

1

If you need to accept both post & get, then you should try something like the code below to retrieve the variable.

$var = 'select1';
if( isset( $_POST[$var] ) ) {
    $id = $_POST[$var];
} else if( isset( $_GET[$var] ) ) {
    $id = $_GET[$var];
} else {
    $id = -1;
}
Sign up to request clarification or add additional context in comments.

7 Comments

Still not working. And trying to get a feedback using <?php echo $id;?> i get the right value....
The $id is still not recognized by the mysql_query(sprintf("UPDATE sarcini1 SET file_name = '%s' WHERE id_sarcina = '%s'", $my_upload->file_copy, $id));
I am not sure where you tried to echo $id; (assuming just before the call to mysql_query) so you're sure you actually get there. Also not sure if you get any error messages or any kind of output, if yes it may be useful to provide them.
As a side note, you probably should use mysqli extension instead of mysql (or ADOdb or PDO), and use bind variables instead of building the query with sprintf
Thank you for your time. So, I inserted an echo $id after your ideea and before if(isset($_POST['Submit'])) {..... bla, bla and it shows the right id.I found a free php code here linkand I intend to update some of my records uploading a pdf file (the copy of the invoice) and saving the name as file_name in sarcini1 table.
|
1

You are using both GET and POST at the same time. As far as I can see, this condition is not returning 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.