Guest User

code snippet(debug)

a guest
Jan 15th, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. The problem is, you're not specifying and using the connection handler anywhere in test.php. Return the connection handler from the startcon() method and use it in mysql_query() method. Below is the working code.
  2.  
  3. Sidenote: Please don't use mysql_ database extensions, they are deprecated as of PHP 5.5 and are removed altogether in PHP 7.0. Use mysqli or PDO extension instead.
  4.  
  5.  
  6. connection.php
  7.  
  8. <?php
  9.     class DBcon
  10.     {
  11.         // property declaration
  12.         public $ip = "localhost";
  13.         public $user = "root";
  14.         public $pass = "";
  15.         public $db = "stackoverflow";
  16.  
  17.         // method declaration
  18.         public function startcon()
  19.         {
  20.             $con=mysql_connect($this->ip,$this->user,$this->pass);
  21.             mysql_select_db($this->db, $con);
  22.             return $con;
  23.         }
  24.     }
  25. ?>
  26.  
  27.  
  28.  
  29. test.php
  30.  
  31. <?php
  32.     include_once("connection.php");
  33.    
  34.     $c = new DBcon();
  35.     $connection = $c->startcon();
  36.     global $array ;
  37.  
  38.     $s = "SELECT  B.question, B.ansSel FROM quizcheck B
  39.         WHERE EXISTS
  40.         (SELECT * FROM quizes A
  41.         WHERE A.question = B.question AND A.Answer = B.ansSel)";
  42.     $result = mysql_query($s, $connection);
  43.  
  44.     $r = mysql_fetch_array($result) or die(mysql_error());
  45.    
  46.     if(mysql_num_rows($r) >= 1){
  47.         echo "correct";
  48.     }else{
  49.         echo "list of wrongs";
  50.     }
  51. ?>
Add Comment
Please, Sign In to add comment