header location with id in php

0 votes

Can a row ID be passed to header()? I tried putting header() inside of an if statement, but I consistently received the following message:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

Here's my code:

$result = mysqli_query($db_con,$query);
$target="Admin/upload/otherPic/".basename($_FILES['image']['name']);
if ($result){
    if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
        echo "<script>
            alert('Record updated successfully!');
            </script>";
        header("Location: admin-viewacc.php?id='$result['id'];'");
    }
    else{
        echo "Error updating record: " . mysqli_error($db_con);
    }
}

 

Aug 6, 2022 in PHP by Kithuzzz
• 38,000 points
1,912 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

Error:Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line 23

Hello @kartik, This error message gets triggered when anything is ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,840 points
5,681 views
0 votes
1 answer

How to run process with realtime output in PHP?

Hello @kartik, This worked for me: $cmd = "ping ...READ MORE

answered Oct 20, 2020 in PHP by Niroj
• 82,840 points
4,144 views
0 votes
1 answer

How do I get the last inserted ID of a MySQL table in PHP?

Hello @kartik, If you're using PDO, use PDO::lastInsertId. If you're ...READ MORE

answered Oct 22, 2020 in PHP by Niroj
• 82,840 points
2,232 views
0 votes
1 answer

How to remove a child with a specific attribute, in SimpleXML for PHP?

Hii, Just unset the node: $str = <<<STR <a> ...READ MORE

answered Nov 5, 2020 in PHP by Niroj
• 82,840 points
4,294 views
0 votes
1 answer

How to find Object ID in PHP?

Hello @kartik, Use spl_object_hash() for that. It returns an unique identifier ...READ MORE

answered Nov 16, 2020 in PHP by Niroj
• 82,840 points
1,944 views
0 votes
1 answer

How do I resize pngs with transparency in PHP?

Hello @kartik, you need to set the blending ...READ MORE

answered Nov 23, 2020 in PHP by Niroj
• 82,840 points
2,453 views
0 votes
1 answer

Simple question regarding PHP, Wordpress & Yoast SEO

the way the search engine displays your ...READ MORE

answered Feb 14, 2022 in Others by narikkadan
• 63,600 points
498 views
0 votes
1 answer

How to fix "Headers already sent" error in PHP

The functions that send and modify the ...READ MORE

answered Feb 17, 2022 in Others by Aditya
• 7,680 points
7,179 views
0 votes
0 answers

PHP header(Location: ...): Force URL change in address bar

I have a new webpage but the ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
3,422 views
0 votes
0 answers

PHP generate file for download then redirect

I have a PHP app that creates ...READ MORE

Jun 20, 2022 in PHP by narikkadan
• 63,600 points
1,009 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP