title: SQL Error 1452 only occurs when Inserting row from PHP page using auto_increment
body: <p>EDIT: I tried an INSERT INTO from PhpMyAdmin. I noticed If I just do the GenreName and dont put an ID, the AutoIncrement is giving me a row ID of 2147483647 :
      INSERT INTO Genres( GenreName ) 
      VALUES ('testFromPhpmyAdmin')</p>
  
  <p>I got an error like this before when working directly in the MySQL database, but everything I tried from that past error on this new one is not working. I have exhausted as many StackOverflow posts about this as I could but none of the solutions ended up working. I have definitely checked that the ID is available in both of the tables. Also, it worked when I had the page simply have a form with text inputs for AlbumID and AlbumName, but I wanted to get rid of text entry for AlbumID as its autoincremented in the MySQL DB so users should not have to type/guess a new ID.</p>
  
  <p>Error: SQL Error: 
  Errno: 1452
  Error: Cannot add or update a child row: a foreign key constraint fails (<code>andrew79_601</code>.<code>Albums</code>, CONSTRAINT <code>Albums_ibfk_2</code> FOREIGN KEY (<code>ArtistID</code>) REFERENCES <code>Artists</code> (<code>ArtistID</code>))</p>
  
  <p>This happens when Im on on my addalbum.php page.
  This is the code I'm using:
  <em>addalbum.php</em></p>
  
  <pre><code>&lt;?php 
  
  //Get All genre
  include 'dbconnect.php';
  $sql_genre = "SELECT GenreID FROM Genres";
  $genre_data = $mysqli-&gt;query($sql_genre);
  
  // Get all artists
  $sql_artist = "SELECT ArtistID FROM Artists";
  $artists_data = $mysqli-&gt;query($sql_artist);
  
  ?&gt;
  
  &lt;form action="addalbumssrv.php" method="post"&gt;
  
  &lt;!-- AlbumID:&lt;input type="text" name="AlbumID" id="AlbumID"/&gt;&lt;/br&gt; --&gt;
  Album Name:&lt;input type="text" name="AlbumName" id="AlbumName"/&gt;&lt;/br&gt;
      &lt;div&gt;                    
                          &lt;div class="dev-left"&gt;Genre ID:&amp;nbsp;&lt;/div&gt;
                          &lt;div class="dev-left"&gt;
                              &lt;?php if ($genre_data-&gt;num_rows &gt; 0) { ?&gt;
                                  &lt;select name="genre" style="width: 150px;"&gt;
                                      &lt;option value=""&gt;------Select-------&lt;/option&gt;
                                      &lt;?php while ($row = $genre_data-&gt;fetch_assoc()) {
                                          ?&gt;
                                          &lt;option value="&lt;?php echo $row['ID']; ?&gt;"&gt;
                                              &lt;?php echo $row['GenreID']; ?&gt;
                                          &lt;/option&gt;
                                      &lt;?php }
                                      ?&gt;
                                  &lt;/select&gt;
                                  &lt;?php
                              } else {
                                  echo 'No Genre ID Found';
                              }
                              ?&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
          &lt;!--Artist drop down--&gt;
                      &lt;div&gt;                    
                          &lt;div class="dev-left"&gt;Artist ID:&amp;nbsp;&lt;/div&gt;
                          &lt;div class="dev-left"&gt;
                              &lt;?php if ($artists_data-&gt;num_rows &gt; 0) { ?&gt;
                                  &lt;select name="artist" style="width: 150px;"&gt;
                                      &lt;option value=""&gt;------Select-------&lt;/option&gt;
                                      &lt;?php while ($row = $artists_data-&gt;fetch_assoc()) {
                                          ?&gt;
                                          &lt;option value="&lt;?php echo $row['ID']; ?&gt;"&gt;
                                              &lt;?php echo $row['ArtistID']; ?&gt;
                                          &lt;/option&gt;
                                      &lt;?php }
                                      ?&gt;
                                  &lt;/select&gt;
                                  &lt;?php
                              } else {
                                  echo 'No Artist ID Found';
                              }
                              ?&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
  &lt;input type="submit"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><em>addalbumssrv.php:</em></p>
  
  <pre><code>&lt;?php
  
  //include 'dbconnect.php';
  
  $link = new mysqli('127.0.0.1', 'andrew79_601', 'csis601', 'andrew79_601');
  if ($link-&gt;connect_errno) {
      echo "Error: Failed to make a MySQL connection, here is why: &lt;/br&gt;";
      echo "Errno: " . $link-&gt;connect_errno . "&lt;/br&gt;";
      echo "Error: " . $link-&gt;connect_error . "&lt;/br&gt;";
  
      exit;
  }
  
  // Escape user inputs for security
  $AlbumID = mysqli_real_escape_string($link, $_REQUEST['AlbumID']);
  $AlbumName = mysqli_real_escape_string($link, $_REQUEST['AlbumName']);
  
  
  
  // attempt insert query execution
  //$sql = "INSERT INTO Albums (AlbumID, AlbumName) VALUES ('$AlbumID', '$AlbumName')";
  $sql = "INSERT INTO Albums (AlbumName) VALUES ('$AlbumName')";
  
  if (!$result = $link-&gt;query($sql)) {
      echo "Error: SQL Error: &lt;/br&gt;";
      echo "Errno: " . $link-&gt;errno . "&lt;/br&gt;";
      echo "Error: " . $link-&gt;error . "&lt;/br&gt;";
  
      exit;
  }
  ?&gt;
  &lt;script&gt;
  window.location='albums.php';
  &lt;/script&gt;
  </code></pre>
  
  <p>Table structure:
  <a href="https://imgur.com/xziavSk" rel="nofollow noreferrer">http://imgur.com/xziavSk</a></p>