title: Unknown database error
body: <p>I'm developing a dynamic website. I have two pages , first one called "testcreatorpd1003.php" and the other one "databaseconnectpd1003.php" . Everything was working fine until i found that else part of databaseconnectpd1003.php is executing each time i insert some data.</p>
  
  <p>Following are the codes :<br></p>
  
  <p><strong>testcreatorpd1003.php</strong></p>
  
  <pre><code>&lt;body oncontextmenu="return false;"&gt;
  &lt;?php
  if (isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] == true &amp;&amp; $_SESSION['user']=='administrator') 
  {
  
  echo'&lt;div class="usercheck"&gt;&lt;code&gt;&lt;strong&gt;WELCOME , YOU ARE LOGGED IN. QUICK LINKS :&lt;/strong&gt;&amp;#160;&amp;#160;&lt;a class="panelbox" href="admin.php"&gt;ADMIN PANEL&lt;/a&gt;&lt;/code&gt; || &lt;code&gt;&lt;a class="panelbox" href="logout.php"&gt;LOGOUT&lt;/a&gt;&lt;/code&gt; &lt;/div&gt;';
  } 
  elseif (isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] == true &amp;&amp; $_SESSION['user']=='user')
  {
  echo'&lt;div class="usercheck"&gt;&lt;code&gt;&lt;strong&gt;WELCOME , YOU ARE LOGGED IN. QUICK LINKS :&lt;/strong&gt;&amp;#160;&amp;#160;&lt;a class="panelbox" href="user.php"&gt;USER PANEL&lt;/a&gt;&lt;/code&gt; &amp;#160; || &amp;#160;&lt;code&gt;&lt;a class="panelbox" href="logout.php"&gt;LOGOUT&lt;/a&gt; &lt;/code&gt;&lt;/div&gt;';  
   }
  
  else
  {
  header('Location: faculty-login.php');
  }
  ?&gt;
  &lt;div class="addquestion"&gt;
  &lt;form action="databaseconnectpd1003.php" method="post"&gt;
  &lt;center&gt;
  &lt;b&gt;QUESTION&lt;/b&gt; :&lt;br&gt;
  &lt;textarea name="question" rows="2" cols="50" placeholder="Please write your question here..." style="margin: auto; width: 70%;"&gt;&lt;/textarea&gt;
  &lt;/textarea&gt;&lt;br&gt;
  &lt;b&gt;OPTIONS&lt;/b&gt; :&lt;br&gt;
  &lt;strong&gt;OPTION ID : 1&lt;/strong&gt;
  &lt;input type="text" class="input-generic" name="o1" placeholder="Write first option here"&gt;&lt;br&gt;
  &lt;strong&gt;OPTION ID : 2&lt;/strong&gt;
  &lt;input type="text" class="input-generic" name="o2" placeholder="Write second option here"&gt;&lt;br&gt;
  &lt;strong&gt;OPTION ID : 3&lt;/strong&gt;
  &lt;input type="text" class="input-generic" name="o3" placeholder="Write third option here"&gt;&lt;br&gt;
  &lt;strong&gt;OPTION ID : 4&lt;/strong&gt;
  &lt;input type="text" class="input-generic" name="o4" placeholder="Write fourth option here"&gt;&lt;br&gt;
  &lt;strong&gt;OPTION ID : 5&lt;/strong&gt;
  &lt;input type="text" class="input-generic" name="o5" placeholder="Write fifth option here"&gt;&lt;br&gt;
  &lt;hr&gt;
  &lt;b&gt;Correct ID number&lt;/b&gt; :
  &lt;input type="text" name="answer" class="input-generic" placeholder="1 OR 2 OR 3 OR 4 OR 5"&gt;&lt;br&gt;
  &lt;b&gt;Max. Marks alloted&lt;/b&gt; :
  &lt;input type="text" class="input-generic" name="marks"&gt;&lt;br&gt;
  &lt;input type="submit" name="submit"&gt;
  &lt;input type="reset" name="reset"&gt;
  &lt;/center&gt;   
  &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><hr>
  <strong>databaseconnectpd1003.php</strong></p>
  
  <pre><code>&lt;body oncontextmenu="return false;"&gt;
  &lt;?php
  if (isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] == true &amp;&amp; $_SESSION['user']=='administrator') 
  {
  echo'&lt;div class="usercheck"&gt;&lt;code&gt;&lt;strong&gt;WELCOME , YOU ARE LOGGED IN. QUICK LINKS :&lt;/strong&gt;&amp;#160;&amp;#160;&lt;a class="panelbox" href="admin.php"&gt;ADMIN PANEL&lt;/a&gt;&lt;/code&gt; || &lt;code&gt;&lt;a class="panelbox" href="logout.php"&gt;LOGOUT&lt;/a&gt;&lt;/code&gt; &lt;/div&gt;';
  } 
  elseif (isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] == true &amp;&amp; $_SESSION['user']=='user')
  {
  echo'&lt;div class="usercheck"&gt;&lt;code&gt;&lt;strong&gt;WELCOME , YOU ARE LOGGED IN. QUICK LINKS :&lt;/strong&gt;&amp;#160;&amp;#160;&lt;a class="panelbox" href="user.php"&gt;USER PANEL&lt;/a&gt;&lt;/code&gt; &amp;#160; || &amp;#160;&lt;code&gt;&lt;a class="panelbox" href="logout.php"&gt;LOGOUT&lt;/a&gt; &lt;/code&gt;&lt;/div&gt;';  
  }
  else
  {
  header('Location: faculty-login.php');
  }
  ?&gt;
  &lt;div class="testcategory"&gt;
  &lt;?php
  $servername="localhost";
  $username="root";
  $pass="";
  $db="onlinetest";
  $connect=mysqli_connect($servername,$username,$pass,$db);
  if($connect)
  {
  $question=$_POST["question"];
  $option1=$_POST["o1"];
  $option2=$_POST["o2"];
  $option3=$_POST["o3"];
  $option4=$_POST["o4"];
  $option5=$_POST["o5"];
  $answer=$_POST["answer"];
  if($answer==1)
  {
  $answertext=$_POST["o1"];
  }
  elseif($answer==2)
  {
  $answertext=$_POST["o2"];
  }
  elseif($answer==3)
  {
  $answertext==$_POST["o3"];
  }
  elseif($answer==4)
  {
  $answertext==$_POST["o4"];
  }
  else
  {
  $answertext==$_POST["o5"];
  }
  $marks=$_POST["marks"];
  $sql="INSERT into pd1003 values ('$question','$option1','$option2','$option3','$option4','$option5',$answer','$answertext','$marks')";
  if(mysqli_query($connect,$sql))
  {
  echo"Question was added";
  echo"&lt;em&gt; &lt;a href='testcreatorpd1003.php'&gt;Add another question&lt;/a&gt;&lt;/em&gt;";
  }
  else
  {
  echo"Some error occurred . If error persists , please contact administrator".mysqli_connect_error();
  echo"&lt;em&gt; &lt;a href='testcreatorpd1003.php'&gt;Add another question&lt;/a&gt;&lt;/em&gt;";
  }
  
  }
  
  else{
  die("There was some error connecting to database. Please try again".mysqli_connect_error());
  
  }
  mysqli_close($connect);
  ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <hr>
  
  <p>Please tell me what I'm doing wrong. Everytime I insert a question with options and everything it says "Some error occurred . If error persists , please contact administrator". Everything looks fine to me. Please help !!</p>
  
  <p>Name of database is : onlinetest
  Name of table:pd1003</p>