Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6706015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:28:14+00:00 2026-05-26T07:28:14+00:00

I have the following code that displays a given image using php echo id

  • 0

I have the following code that displays a given image using php echo id from a mysql table. The php is:

    <?php include 'dbc.php'; page_protect();


$id=$_GET['id'];


if(!checkAdmin()) {header("Location: login.php");
exit();
}

$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
$path   = rtrim($login_path, '/\\');

foreach($_GET as $key => $value) {
    $get[$key] = filter($value);
}

foreach($_POST as $key => $value) {
    $post[$key] = filter($value);
}   
?>


<?php 
if($_FILES['photo']) 
{
    $target = "images/furnishings/"; 
    $target = $target . basename( $_FILES['photo']['name']); 

   $title = mysql_real_escape_string($_POST['title']); 
    $pic = "images/furnishings/" .(mysql_real_escape_string($_FILES['photo']['name']));
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{

    mysql_query("update `furnishings` set `photo`='$pic' WHERE id='$id'") ;     

    echo "Image updated"; 
} 
else 
{ 
    echo "Please select a new image to upload"; 

}
} 
?>

The HTML is:

<form enctype="multipart/form-data" action="editfurnimage.php" method="POST">
  <table width="450" border="2" cellpadding="5"class="myaccount">
     <tr>
       <td width="35%" class="myaccount">Current Image: </td>
       <td width="65%"><img src='<?php

mysql_select_db("dbname", $con);
mysql_set_charset('utf8');

$result = mysql_query("SELECT * FROM furnishings WHERE id='$id'");

while($row = mysql_fetch_array($result))
{
    echo '' . $row['photo'] . '';

}
mysql_close($con);
?>' style="width:300px; height:300px;"></td>
    </tr>
   <tr>
       <td class="myaccount">New Image: </td>
       <td><input type="file" name="photo" /></td>
    </tr>
     <tr>
       <td colspan="2"><input type="submit" class="CMSbutton" value="Add" /></td>
     </tr>
  </table>
</form>

While the coding is adding the new image to the server, the mysql table doesnt seem to be updating with the new image – in fact no changes are being made – when I adjust the line:

mysql_query("update `furnishings` set `photo`='$pic' WHERE id='$id'") ; 

to:

mysql_query("update `furnishings` set `photo`='$pic' WHERE id='8'") ; 

it works though so assuming the issue is lying with this part of the code but not sure how to correct the code to pull the $id into the php correctly.

Finally, when the script runs I am trying to get the page “editfurnimage.php?id=$id” to reload following the user clicking the Add button – at the moment the page that is returned is “editfurnimage.php” which obviously doesnt show up any data from the table.

Any help much appreciated – and as always feel free to tear my coding apart – still learning!!

Thanks
JD

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:28:14+00:00Added an answer on May 26, 2026 at 7:28 am

    try to remove your single quotes around $id.
    If your id field in the database in an int, then quotes should not be used around it.

    EDIT: Missed this one – Where is $_GET[‘id’] being sent from, because your form sure isn’t sending any id in the $_GET scope? Try adding the input with a name of ‘id’ and a value for it in to your form. also, use $_POST in your php file, not $_GET.

    In your php, replace:

    $id=$_GET['id'];
    

    With

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

    Then in your html add:

    <input type="hidden" name="id" value="<?php echo $id; ?>"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that loads a user's Active Directory DirectoryEntry object from
I have following code that does not work due to a being a value
I have following code snippet that i use to compile class at the run
I have the following code that shows either a bug or a misunderstanding on
I have the following code that won't compile and although there is a way
I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie
I have the following code that creates two objects (ProfileManager and EmployerManager) where the
I have the following code that I need to add an additonal object to
I have the following code that creates a serverside object of the xmlhttp class.
I have the following code that controls the presentation of an interdependent group. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.