Working on echoing the users questions out so far I can insert the values and this is working thru the php admin but its not working thru , the form on the users profile page?
The error says ,"Call to a member function query() on a non-object in profile.php on line 82" The php code on this line is as follows
   $query1=$db->query("SELECT id,title,question,username FROM  QnA WHERE username='$dbusername'");
The rest of profile.php is below
   <?php 
     session_start();
     $dusername=$_GET['username'];
    if (isset($dusername)){
        require('connect.php');
        $userquery =$db->query("SELECT id,firstname,username,lastname,email FROM users WHERE username = '".$dusername."'");
                while ($row =$userquery->fetch()){
                        $id=$row["id"];
                        $dbusername =$row["username"];
                        $dfirstname = $row["firstname"];
                        $demail =$row["email"];
                        $dlastname =$row["lastname"];
                        }
    }
 ?>
  <html>
   <head><title><?php  echo $dfirstname;?></title>
    <link rel="stylesheet" href="stylesheets/profile.css" type="text/css">
 </head>
 <body>
    <div id="container">
<?php
echo'
 <div id="qform"><center>
  <form action="ask.php" method="post">
   <b>Title</b>
   <br/>
   <input type ="text" name="title"/>
   <br/>
   <b>Question</b>
   <br/>
   <textarea name="question"></textarea>
   <br/>
   <b>This is to make sure your not a robot  2+2=</b>
   <input type="text" name="plus"/>
   <br/>
   <input type="submit" value="Submit"name="submit"/> 
   </form></center>
   </div>
    ';
?>  
<div id="questions">
 <?php 
   $query1=$db->query("SELECT id,title,question,username FROM  QnA WHERE username='$dbusername'");
  //$query2=$db->query("SELECT * FROM answers");
   while($asked=$query1->fetch()){
    if($asked['username']==$dbusername){
     echo '<div class="asked"><b>Title</b><br/><b> ',$asked['title'],'</b>   <hr/><br/><b>Question</b><br/><b>',$asked['question'],'</b></div><br/><br/>';
   }
     else if(!$asked['username']==$dbusername){
          error_reporting(E_ALL);
    echo 'No questions have been asked';
        }
 }
     ?>
 </div>
 </div>
 </center>
 </body>
</html>
The form is in the profile.php the action for the form is in a separate file named ask.php which is below.
   <?php
   //form action below
   require('profile.php');
   session_start();
   require('connect.php');
   $plus=$_POST['plus'];
   $title=$_POST['title'];
   $question=$_POST['question'];
   $dusername=$_SESSION['username'];
         if(isset($_POST['submit'])){
          if(!empty($_POST['title']) && !empty($_POST['question'])&& $plus==4){
              $query="INSERT INTO `QnA` (id,title,question,username) VALUES (?,?,?,?)";
              $query=$db->prepare($query);
              $query->execute(array(' ',$title,$question,$dusername));
                echo'succes';
                header("Location: profile.php");
            }
         else{
             error_reporting(E_ALL);
             echo " Fill in all Slots or you gave the wrong answer to the security question";
            }
         }
?>
 
     
     
     
     
    