echo not printing after form block [duplicate]

9
October 11, 2018, at 4:30 PM

This question already has an answer here:

  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP 27 answers
  • How to display errors for my MySQLi query? [duplicate] 3 answers
  • Can I mix MySQL APIs in PHP? 4 answers

Im not sure why echo isn't printing in this piece of code. I've never had problems with echo not printing before, but it seems after a form block it doesn't want to print?

There are two echo statements that aren't printing after the form block. I'm not sure what else to add, the printf function works fine at the start of the code. Just seems nothing else will print to screen.

<?php
$connection = mysqli_connect("localhost", "root", "", "movies");
if(!$connection){
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
printf("Host information: %s\n", mysqli_get_host_info($connection));
/*$file = "MoviesCSV.csv";
$file_open = fopen($file,"r");
while(($csv = fgetcsv($file_open, 1000000, ",")) !== false)
{
    $title = $csv[0];
    $studio = $csv[1];
    $status = $csv[2];
    $sound = $csv[3];
    $version = $csv[4];
    $retPrice = $csv[5];
    $rating = $csv[6];
    $year = $csv[7];
    $genre = $csv[8];
    $aspect = $csv[9];
    $sql = "INSERT INTO movies
            (Title, Studio, Status, Sound, Versions, RecRetPrice, Rating, Year, Genre, Aspect)
            values 
            ('$title', '$studio', '$status', '$sound', '$version', '$retPrice', '$rating', '$year', '$genre', '$aspect')";
        if(mysqli_query($connection, $sql) === true) {
            echo("Successfully inserted into database. <br/>\n");
        }else{
            printf(mysqli_error($connection));
        }
}*/
//mysqli_close($connection);
?>
<form action="" method="post">
    Title: <input type="text" name="title"/><br/>
    Genre: <input type="text" name="genre"/><br/>
    Rating: <input type="text" name="rating"/><br/>
    Year: <input type="text" name="year"/><br/>
    <p><input type="submit" value="click to submit"/></p>
</form>
<?php
  if(isset($_POST['submit'])){
    $fields = array('title', 'genre', 'rating', 'year');
      $conditions = array();
      foreach($fields as $field){
        if(isset($_POST[$field]) && $_POST[$field] != ''){
          $conditions[] = "'$field' LIKE '%" . mysqli_real_escape_string($connection, $_POST[$field]) . "%'";
      }
  }
  $query = "SELECT Title, Studio, Status, Sound, Versions, RecRetPrice, Rating, Year, Genre, Aspect FROM movies";
  if(count($conditions) > 0){
    $query .= " WHERE " . implode (' AND ', $conditions);
  }
  echo "$query";
  $result = mysqli_query($connection, $query) or die(mysql_error());
  if(isset($_POST['submit'])){
    while($row = mysqli_fetch_assoc($result)){
        $title = $row['Title'];
        $studio = $row['Studio'];
        $status = $row['Status'];
        $sound = $row['Sound'];
        $version = $row['Versions'];
        $retPrice = $row['RecRetPrice'];
        $rating = $row['Rating'];
        $year = $row['Year'];
        $genre = $row['Genre'];
        $aspect = $row['Aspect'];
        echo("Title: $title<br>Studio: $studio<br>");
      }
    }
  }
   mysqli_close($connection);
?>
READ ALSO
Php mysql insert/update from json

Php mysql insert/update from json

hello i have a problem insert data to mysql working but i need if not exist data create if exist update all rowNow after each refresh page add same data but not updating

8
$_POST is empty in push notification response (PHP)

$_POST is empty in push notification response (PHP)

Can anybody tell me how to get the response data from a push notification responseI am currently only able to get data from headers, but $_POST is an empty array

25
Email Open Rate Tracker - Differences in email client

Email Open Rate Tracker - Differences in email client

I've implemented a very common approach to email open rate tracking using a 1x1px transparent image:

33