Echo issue

Hey :blush:

Have 2 issues:

  1. How do I correct the image size…both should be equal once uploaded.
  2. The image uploads perfectly but username and title doesnt show. Ive placed the ECHO command in my code but it only works for the image. Here is my code:
<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" />
<textarea name="comments" id="comments" style="font-family:sans-serif;font-size:1.2em;">
</textarea>
   <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>       
  <input type="submit" value="Submit" name="submit">
</form>
      </div>
    </div>
  </div>
</div>
 
   <br>
  <br>
  <br>
  <br>
<div class="row row-cols-1 row-cols-md-2 g-4">
<?php
 require_once "db.php";
    $sql = "SELECT imageId FROM output_images ORDER BY imageId DESC"; 
    $result = mysqli_query($conn, $sql);

//  Loop thru comments and display all of them
while($row = mysqli_fetch_array($result)) {
    printf("%s (%s)\n", $row["username"], $row["comment"],$row["imageId"]); 
?>
    <div class="row">
        <a href="pro.php">
            <div class="card">
                 <img src="imageView.php?image_id=<?php echo $row["imageId"]; ?>" class="card-img-top" alt="...">
	        <div class="card-body">
                    <h5 class="card-title"><?php echo (int)$_POST['username']; ?> </h5>
                    <p class="card-text"><?php echo (int)$_POST['comment']; ?> </p>
                </div>

I appreciate the help :heart:

Echo vs Printf:

" The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print ."

As far as image sizing goes… you haven’t added any params or attributes… or styles/classes to adjust it in any way. So you get what you get. So being ‘equal’ is a bit difficult if you aren’t somehow defining the other images dimensions either.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service