Mekaboo Posted November 14, 2021 Share Posted November 14, 2021 (edited) Hey☺️ I implemented a script into my site to upload images. I added a Comment Column within the script's already made table so users can add words with the images. Here is my code: DB connect(don't know if I added comment correctly) <?php require_once "db.php"; if(isset($_GET['image_id'])) { $sql = "SELECT imageType,imageData,comment FROM output_images WHERE imageId=" . $_GET['image_id']; $result = mysqli_query($conn, $sql) or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysqli_error($conn)); $row = mysqli_fetch_array($result); header("Content-type: " . $row["imageType"]); echo $row["imageData"]; echo $row["comment"]; } mysqli_close($conn); ?> Form: <form name="frmImage" enctype="multipart/form-data" action="" method="post" class="frmImageUpload"> <label>Upload Image File:</label><br/> <input name="userImage" type="file" class="inputFile" /><br> Write: <input type="text" name="comment"><br> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <input type="submit" value="Submit" name="submit"> </form> Question is: how do I attach "comment" column within the DB connect so content will store as well as display? Thank ya❤️ Edited November 14, 2021 by Mekaboo Quote Link to comment https://forums.phpfreaks.com/topic/314228-adding-a-new-column-to-already-made-script/ Share on other sites More sharing options...
Barand Posted November 14, 2021 Share Posted November 14, 2021 If you are outputting an image from a DB blob field, then here's an example... // EMULATE DATA FROM THE DATABASE $type = 'image/png'; $comments = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.'; $image_data = file_get_contents('images/snowman.PNG'); // OUTPUT THE DATA echo "<div style='width:396;'> <img src='data:{$type};base64," . base64_encode( $image_data ) . "' width='394' height='393'> <p>$comments</p> "; RESULT 2 1 Quote Link to comment https://forums.phpfreaks.com/topic/314228-adding-a-new-column-to-already-made-script/#findComment-1592065 Share on other sites More sharing options...
Mekaboo Posted November 15, 2021 Author Share Posted November 15, 2021 @Barand☺️ Thank ya for the response but I have this already set up. I want to add a column within this code: <?php require_once "db.php"; if(isset($_GET['image_id'])) { $sql = "SELECT imageType,imageData,comment FROM output_images WHERE imageId=" . $_GET['image_id']; $result = mysqli_query($conn, $sql) or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysqli_error($conn)); $row = mysqli_fetch_array($result); header("Content-type: " . $row["imageType"]); echo $row["imageData"]; echo $row["comment"]; } mysqli_close($conn); ?> so that the output you gave me works. As of now the image output works but not the comment Quote Link to comment https://forums.phpfreaks.com/topic/314228-adding-a-new-column-to-already-made-script/#findComment-1592096 Share on other sites More sharing options...
ginerjm Posted November 15, 2021 Share Posted November 15, 2021 OK - when I rearranged your code to read thru it I see this: require_once "db.php"; if(isset($_GET['image_id'])) { $sql = "SELECT imageType,imageData,comment FROM output_images WHERE imageId=" . $_GET['image_id']; $result = mysqli_query($conn, $sql) or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysqli_error($conn)); $row = mysqli_fetch_array($result); header("Content-type: " . $row["imageType"]); echo $row["imageData"]; echo $row["comment"]; } mysqli_close($conn); which looks like you are outputting the comment field. If you are not seeing anything perhaps it is not in the db. Have you taken a look at your table with phpmyadmin to see if it is actually there? Quote Link to comment https://forums.phpfreaks.com/topic/314228-adding-a-new-column-to-already-made-script/#findComment-1592105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.