An example connect is initialized to include 'conf.php'; Help to find and fix the error:

Warning: mysql_query() expects parameter 2 to be resource, null given in U:\home\project\www\core.php on line 12

core.php:

  <?php include 'conf.php'; class Addpostdb{ var $name; var $text; function add($name,$text){ $query="INSERT INTO posts VALUES ( '$name','$text')"; if (mysql_query($query, $connect) or die("error:" . mysql_error())){ echo 'Выполнено'; } } } class Viewpost{ function view(){ $result=mysql_query('SELECT * FROM `posts`'); while($row=mysql_fetch_array($result)) { echo $row['name']. '<p>'.$row['post']; } } } ?> 

    3 answers 3

    You pass the variable $ connection to the mysql_query function with the second parameter, which is not initialized anywhere.

      If the variable is initialized in conf.php, then you need to do this:

        ... function add($name,$text){ global $connect; $query="INSERT INTO posts..... 
         $connect 

        just take it away, you hardly have 10 connections there ...

        and further

        ALL WHO READ THIS POST, ATTENTION !!!

        Never write code with classes in the way the TS does, and it is terrible without the classes! the meaning of what you wrote classes ??? I'm in shock ... take a php tutorial and read! and then they say that the language is bad, here such people need to get their hands from one place, poor puh ... that he suffers ...