Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- 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.
- connection.php
- <?php
- class DBcon
- {
- // property declaration
- public $ip = "localhost";
- public $user = "root";
- public $pass = "";
- public $db = "stackoverflow";
- // method declaration
- public function startcon()
- {
- $con=mysql_connect($this->ip,$this->user,$this->pass);
- mysql_select_db($this->db, $con);
- return $con;
- }
- }
- ?>
- test.php
- <?php
- include_once("connection.php");
- $c = new DBcon();
- $connection = $c->startcon();
- global $array ;
- $s = "SELECT B.question, B.ansSel FROM quizcheck B
- WHERE EXISTS
- (SELECT * FROM quizes A
- WHERE A.question = B.question AND A.Answer = B.ansSel)";
- $result = mysql_query($s, $connection);
- $r = mysql_fetch_array($result) or die(mysql_error());
- if(mysql_num_rows($r) >= 1){
- echo "correct";
- }else{
- echo "list of wrongs";
- }
- ?>
Add Comment
Please, Sign In to add comment