title: How to fix Undefined variable error in PHP
body: <p>I'm doing this for an assessment and I'm nearly done but every time I try updating or editing my database with PHP code it gives the Undefined variable error</p>
  
  <p>I've tried isolating the code that it says is causing the error and fixing it but whatever I do it never works</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form id = "add_books_form" name = "new_book" method = "post" action = "book_processings.php"&gt;
  
              &lt;div id = "inputs"&gt;&lt;label&gt;ISBN  &lt;/label&gt;&lt;input id = "elements" type = "text" maxlength = "30" name = "ISBN" required/&gt;&lt;br&gt;&lt;/div&gt;
              &lt;div id = "inputs"&gt;&lt;label&gt;Title  &lt;/label&gt;&lt;input id = "elements" type = "text" maxlength = "100" name = "Title" required/&gt;&lt;br&gt;&lt;/div&gt;
              &lt;div id = "inputs"&gt;&lt;label&gt;Replacement Cost $  &lt;/label&gt;&lt;input id = "elements" type = "number" value = "0.00" step = "0.10" min = "0" max = "99.99" name = "ReplacementCost" required/&gt;&lt;br&gt;&lt;/div&gt;
              &lt;div id = "inputs"&gt;&lt;label&gt;Adult Theme  &lt;/label&gt;&lt;select id = "elements" name = "adult_theme"&gt;
                              &lt;option value = "Y"&gt;Yes&lt;/option&gt;
                              &lt;option value = "N"&gt;No&lt;/option&gt;
                           &lt;/select&gt;&lt;br&gt;&lt;/div&gt;
              &lt;div id = "inputs"&gt;&lt;label&gt;Category  &lt;/label&gt;&lt;select id = "elements" name = 'category'&gt;
                          &lt;?php
                                  while($all_category_rec = mysqli_fetch_assoc($all_category_qrun)){
                                      echo"&lt;option value = '".$all_category_rec['CategoryID']."'&gt;".$all_category_rec['Category']."&lt;/option&gt;";
                                  }
                          ?&gt;
                      &lt;/select&gt;&lt;br&gt;&lt;/div&gt;
              &lt;div id = "inputs"&gt;&lt;label&gt;Author  &lt;/label&gt;&lt;select id = "elements" name = 'author'&gt;
                          &lt;?php
                                  while($all_authors_rec = mysqli_fetch_assoc($all_authors_qrun)){
                                      echo"&lt;option value = '".$all_authors_rec['AuthorID']."'&gt;".$all_authors_rec['FirstName']." ".$all_authors_rec['LastName']."&lt;/option&gt;";
                                  }
                          ?&gt;
                      &lt;/select&gt;&lt;br&gt;&lt;/div&gt;
  
              &lt;div id = "inputs"&gt;&lt;label&gt;Publisher  &lt;/label&gt;&lt;select id = "elements" name = 'publisher'&gt;
                          &lt;?php
                                  while($all_publishers_rec = mysqli_fetch_assoc($all_publishers_qrun)){
                                      echo"&lt;option value = '".$all_publishers_rec['PublisherID']."'&gt;".$all_publishers_rec['PublisherName']."&lt;/option&gt;";
                                  }
                          ?&gt;
                      &lt;/select&gt;&lt;br&gt;&lt;/div&gt;
  
              &lt;div id = "inputs"&gt;&lt;label&gt;Published Year  &lt;/label&gt;&lt;input id = "elements" type = "number" step = "1" max = "2025" min = "1400" value = "2019" name = "YearOfPublication" required/&gt;&lt;br&gt;&lt;/div&gt;
              &lt;input id = "button" type = "submit" name = "submit" value = "Add Book"/&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>if($_POST['submit'] == 'Add Book'){
          $add_book_query = "INSERT INTO books(ISBN, Title, ReplacementCost, AdultContent, Category, AuthorID, YearOfPublication  , PublisherID)
                     VALUES('$ISBN', '$Title', '$ReplacementCost', '$AdultContent', '$CategoryID', '$AuthorID', '$YearOfPublication', '$PublisherID')";
          $add_book_qrun = mysqli_query($dbcon, $add_book_query);
          if(!$add_book_qrun){
              echo"&lt;h3&gt;Data was not entered.&lt;/h3&gt;";
          }else{
              echo"&lt;h3&gt;Data was successfuly enetered.&lt;/h3&gt;";
          }
          echo"&lt;form id = 'proc' name = 'go_back' method = 'post' action = 'add_book.php'&gt;";                                          
              echo"&lt;input id = 'button' type = 'submit' name = 'submit2' value = 'Go Back'/&gt;";
          echo"&lt;/form&gt;";
      }
  </code></pre>
  
  <p>for this query, I am expecting it to add the details I have entered into my database but instead, I get unidentified variable for all my values</p>