Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When retrieving a single row, you do not have to loop through as you asked in the comment in your code.</p> <p>As for the database, what exactly are you storing what does your table structure look like? You could easily save the name of the image in a field and retrieve that and not even get the fullpath ( since there could be more images there )</p> <p><strong>EDIT 1</strong></p> <p>This is one way to solving the empty string insertion issue yes, however the query will have to be different so you'll have to write one which does insert the image, and one that excludes it</p> <p><strong>EDIT 2</strong></p> <p>After you retrieve the image path all you'd have to do now is split the string by using PHP's explode, e.g. $aPath = explode('/', $yourDBfield);, this would give you an array with items split on a /, since the file will always be at the end, simply do this: $image = $aPath[(count($aPath)-1)];, this should give you the image.</p> <p><strong>EDIT 3</strong></p> <p>As requested by the OP,</p> <p>The main query should include the image update, e.g. when the value set is not empty.</p> <pre><code>$edit_sql =$db-&gt;prepare("UPDATE item SET item_name = '$edit_name', item_description = '$edit_description', photopath ='$image' WHERE item_id = '$form_id'"); </code></pre> <p>The other query should exclude <code>photopath</code> = '$image' e.g.</p> <pre><code>$edit_sql =$db-&gt;prepare("UPDATE item SET item_name = '$edit_name', item_description = '$edit_description', WHERE item_id = '$form_id'"); </code></pre> <p>You could also, as mentioned in the comments, add the default path, e.g. <code>$image</code> (not split) to the value of the field when the page is requested, this way you'd only have to write 1 query, and the image would remain the same if untouched.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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