Jump to content

Adding a new column to already made script


Mekaboo

Recommended Posts

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 by Mekaboo
Link to comment
Share on other sites

  • Mekaboo changed the title to Adding a new column to already made script

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

image.png.dae69a6e44bd467aa6fb965396fe0558.png

  • Like 2
  • Great Answer 1
Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.