Jump to content

Recommended Posts

Hey☺️

I received this error:

Fatal error: Uncaught Error: Call to a member function multi_query() on null in /homepages/23/d815730660/htdocs/home.php:345 Stack trace: #0 {main} thrown in /homepages/23/d815730660/htdocs/home.php on line 345

Trying to added multi query within my site. Goal is when a person adds an image and/or text  via form the text changes per post. Result is similar to a social media wall post. Here is my code:
PHP with error line

<?php
 require_once "db.php";
  if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

$sql = "SELECT imageId FROM output_images ORDER BY imageId DESC";
$sql .= "SELECT commentid FROM comment ORDER BY commentid DESC";


///error line
if ($mysqli -> multi_query($sql)) { 
  do {
    // Store first result set
    //  Loop thru comments and display all of them
    if ($result = $mysqli -> store_result()) {
      while ($row = $result -> fetch_row()) {
         printf("%s (%s)\n", $row["username"], $row["commentid"],$row["imageId"]);
      }
     $result -> free_result();
    }
    // if there are more result-sets, the print a divider
    if ($mysqli -> more_results()) {
      printf("-------------\n");
    }
     //Prepare next result set
  } while ($mysqli -> next_result());
}

$mysqli -> close();
 ?>

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>
   <label>Words:</label><br/>      
 <input type="text" id="commentid" name="commentid">
  <br><br>
   <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>       
  <input type="submit" value="Submit" name="submit">
</form>

Result of  form and php
 

<div class="row">
            
              <div class="alert alert-secondary" role="alert">
                <h5 class="alert-content"><?php echo $username;?> </h5>
               <p class="alert-content"><?php echo $commentid;?> </p>
            <div class="alert-footer">
<div class="btn-group">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
   <span style="color: #673147;">
    <i class="fas fa-comment-dots"></i>
     </span>
  </button>
  <ul class="dropdown-menu">
    <form method="POST" id="commentForm">
            <div class="form-group">
                <input type="text" name="name" id="name" class="form-control" placeholder="Enter Name" required />
            </div>
            <div class="form-group">
                <textarea name="comment" id="comment" class="form-control" placeholder="Enter Comment" rows="5" required></textarea>
            </div>
            <span id="message"></span>
            <br>
            <div class="form-group">
                <input type="hidden" name="commentId" id="commentId" value="0" />
                <input type="submit" name="submit" id="submit" class="btn btn-primary" value="Post Comment" />
            </div>
        </form>        
        <br>
        <div id="showComments"></div>   
</div>    
  </ul>
</div>
 </div>
</div>
  </div>
    

 
               
          
     
            <div class="row">
            <div class="card h-100 card-secondary">
              <div class="card-header">
               <h5 class="card-content"><?php echo $username;?> </h5>
              <p class="alert-content"><?php echo $commentid;?> </p></div>
                     <img src="imageView.php?image_id=<?php echo $row["imageId"]; ?>" class="card-img-top" alt="...">
                <div class="card-footer">
  <div class="btn-group">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
     <span style="color: #673147;">
    <i class="fas fa-comment-dots"></i>
       </span>  
  </button>
  <ul class="dropdown-menu dropright">
     <form method="POST" id="commentForm">
            <div class="form-group">
                <input type="text" name="name" id="name" class="form-control" placeholder="Enter Name" required />
            </div>
            <div class="form-group">
                <textarea name="comment" id="comment" class="form-control" placeholder="Enter Comment" rows="5" required></textarea>
            </div>
            <span id="message"></span>
            <br>
            <div class="form-group">
                <input type="hidden" name="commentId" id="commentId" value="0" />
                <input type="submit" name="submit" id="submit" class="btn btn-primary" value="Post Comment" />
            </div>
        </form>        
        <br>
        <div id="showComments"></div>   
</div>    
  </ul>
</div>
 </div>
</div>

Thank ya❤️

Link to comment
https://forums.phpfreaks.com/topic/314192-multi-query-issue/
Share on other sites

Does this work at all, ie, does the form show up?  Curious to know which line is giving you the error?  IE, line 345?  If it is the first appearance of multi-query the message is saying that something is null.  That is most likely the $mysqli variable.

PS - I seem to recall that multiple query statements in places where one can do that kind of thing need a semi to separate the multiple statements.  You are not doing that here.

  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/314192-multi-query-issue/#findComment-1591891
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.