0

My database is connected because other input fields insert the data into a database table. However, one part of the code does not work for some reason although it does work on localhost. I am not sure why this is. Both tables are using the same connection file and variable. Here is the code for the one that does not work:

 <?php
include 'config.php';
$name = $fileName = "";
$sql = "INSERT INTO output_Images(name, fileName, sub, author) VALUES (?,?,?,?)";
$sqll = "SELECT imageId FROM output_Images WHERE fileName = ?";
$fileSize = $_FILES['pdf_file']['size'];
if(isset($_SESSION['loggedin'])){
  if(empty($_POST['title']) && empty($_POST['subject'])){
    $err = "Input Worksheet Info <br><br>";
  }else{
  if(isset($_POST["submit"])){
    if($stmt = mysqli_prepare($conn, $sqll)){
        mysqli_stmt_bind_param($stmt, "s", $fileName);
        $fileName = trim($_FILES["pdf_file"]["name"]);

        if(mysqli_stmt_execute($stmt)){
            mysqli_stmt_store_result($stmt);

            if(mysqli_stmt_num_rows($stmt) == 1){
                $err = "This file name is already taken. <br><br>";
            } else{
              $fileName = $_FILES['pdf_file']['name'];
              $title = $_POST["title"];
              $subject = $_POST["subject"];
              $author = $_SESSION["username"];
            }
          }
if($stmt = mysqli_prepare($conn, $sql)){
      mysqli_stmt_bind_param($stmt, "ssss", $title, $fileName, $subject, $author);
      if(mysqli_stmt_execute($stmt)){
        $err = "success";
      }}
}
}
}
}
 ?>

Now here is the inputs that are taken into the create.php file:

<?php 
  include 'create.php';
  ?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
  </head>
  <body>
    <div class = "title">
      <?php echo $_SESSION['err']; ?>
    </div>
<form class = "main" method="POST" role="form" enctype="multipart/form-data"autocomplete="off">
   <input type="file" name="pdf_file" id="pdf_file" class = "inputfile"accept="application/pdf"required><br><br>
   <input type="text" name="title" placeholder = "Worksheet name" pattern="^[A-Za-z0-9 ]+$"maxlength = "28"required><br><br>
   <select name="subject" required>
     <option value="">Choose subject</option>
     <option value="English">English</option>
     <option value="History">History</option>
     <option value="Math">Math</option>
     <option value="Science">Science</option>
   </select><br><br><br>
   <button id="send" type="submit" name="submit" class="btn btn-success">Submit</button>
</form>
</body>
</html>
  • 1
    What part is not working? And what happens? – bestprogrammerintheworld Apr 12 '20 at 20:14
  • As previous comment stated be more specific, other than that, make sure your tables on local host and server are 100% the same. – ikiK Apr 12 '20 at 23:24
  • It just does not allow my files or information to be uploaded to the database. The whole code is not working for some reason. It works in localhost but not with my online server, Hostinger. – Lucas Thai Apr 13 '20 at 01:22
  • The output_images table is for sure not connecting for me because even after I manually inserted values into my database, I get the error: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in. However, another table, users connects every time. Therefore, I am making connections to the database itself. I'm just not sure what is going on. The code is working just fine in my localhost. Are there any precautionary measures I need to take when connecting a database to an online host besides using the correct username and password? – Lucas Thai Apr 13 '20 at 02:22

1 Answers1

0

I found the answer. I am an idiot and I am sorry for wasting everyone's time, but apparently phpmyadmin tables are case sensitive when using online hosting services, but are not on localhost for some reason.