Note that there are some explanatory texts on larger screens.

plurals
  1. POshow path of image on update form php
    primarykey
    data
    text
    <p>When populating the fields of an update form how can I show the path to the current image like this <img src="https://i.stack.imgur.com/T77u8.png" alt="enter image description here"></p> <p>so that if the user doesn't want to change the image the same image is used. This is what the browser displays: <code>&lt;input type="file" value="uploads/chaps_B.jpg" name="image_edit"&gt;&lt;/input&gt;</code></p> <p>I have a feeling my <code>photopath</code> in not in scope but unsure how to go about fixing it. All variables populate the form and it saves to the db fine just can't figure out the image path.</p> <pre><code> if(isset($_POST['update_submit'])) { $get_products = $db-&gt;prepare("select `photopath` from `item` where `item_id` = '$get_item' LIMIT 1"); $get_products-&gt;execute(); $path= $get_products-&gt;fetchColumn(6); if($_FILES['image_edit']['tmp_name'] != "") { $edit_name = $_POST['item_name']; $edit_description =$_POST['item_description']; $form_id = $_POST['edit_form_id']; $file_dir = "uploads/"; $image = $file_dir. $_FILES['image_edit']['name']; move_uploaded_file($_FILES['image_edit']['tmp_name'], $image); $edit_sql =$db-&gt;prepare("UPDATE item SET item_name = '$edit_name', item_description = '$edit_description', photopath ='$image' WHERE item_id = '$form_id'"); $edit_sql-&gt;execute(); header("Location: manage_items.php"); exit(); } else { $edit_name = $_POST['item_name']; $edit_description =$_POST['item_description']; $form_id = $_POST['edit_form_id']; $edit_sql =$db-&gt;prepare("UPDATE item SET item_name = '$edit_name', item_description = '$edit_description' WHERE item_id = '$form_id'"); $edit_sql-&gt;execute(); header("Location: manage_items.php"); exit(); } </code></pre> <p>UPDATE FORM</p> <pre><code> &lt;form action="item_edit.php" method="post" enctype="multipart/form-data"&gt; &lt;input type = "text" name="item_name" value="&lt;?php echo $item_name ?&gt; "/&gt; &lt;textarea name="item_description"&gt;&lt;?php echo $item_description ?&gt;&lt;/textarea&gt; &lt;p&gt; &lt;img src="&lt;?php echo $image; ?&gt;" width="75" height="75" /&gt;&lt;/p&gt; &lt;input type="file" name="image_edit" /&gt; &lt;input name="edit_form_id" type="hidden" value="&lt;?php echo $get_item ?&gt;"&gt; &lt;p&gt;&lt;input type="submit" name="update_submit" value="Update"/&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit" name="cancel_edit" value="Cancel"/&gt;&lt;/p&gt; &lt;/form&gt; </code></pre> <p>DB STRUCTURE</p> <p><img src="https://i.stack.imgur.com/M2Mit.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload