注意:尝试在第28行的C:\ wamp \ www \ process.php中获取非对象的属性

时间:2015-09-16 17:27:22

标签: fatal-error

indexs.php 这是连接的数据定义

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'Hisham');
define('DB_PASSWORD', 'ahisham199691');
define('DB_DATABASE', 'final');

process.php这是与数据库可能性的连接

<?php 
    include "indexs.php";

    class User{

        public $db;
        public function __Construct(){
            $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);

            if(mysqli_connect_errno()) {

                echo "Error: Could not connect to database.";

            exit;

            }
        }

        /*** for registration process ***/
        public function reg_user($name,$phone,$password){



            $sql="SELECT * FROM users WHERE name='$name' OR phone='$phone'";

            //checking if the username or email is available in db
            $check =  $this->db->query($sql);

            $count_row = $check->num_rows;

            //if the username is not in db then insert to the table
            if ($count_row == 0){
                $sql1="INSERT INTO users SET name='$name',phone='$phone' password='$password'";
                $result = mysqli_query($this->db,$sql1) or die(mysqli_connect_errno()."Data cannot inserted");
                return $result;
            }
            else { return false;}
        }
    }
        $my = new User();
        var_dump($my->db);
?>

问题出在第29行

$check =  $this->db->query($sql);
$count_row = $check->num_rows;

home.php用于填充以使用phpmyadmin将数据添加到数据库

    <?php

include_once 'process.php';
$user = new User();
if (isset($_REQUEST['submit'])){
    extract($_REQUEST);
    $send = $user->reg_user($name,$phone,$password);
    if ($send){
        echo 'regisration succesful!';
    }

}

?>
<form action="home.php" method="post">
    <input type="text" name="name" placeholder="Name"><br>
    <input type="tel" name="phone" placeholder="Phone no."><br>
    <input type="text" name="password" placeholder="Password"><br>
<input type="submit" name="submit" value="Submit"/>
</form>

0 个答案:

没有答案