0

hlo all,
i need to write a code in php oop for registration without using form and data directly goes in the database. i try to write the code for this. i show u that code and help me to correct that or by giving me another code. the database name is

bhumi_regn

and there is an error "

Fatal error

: Call to a member function prepare() on a non-object in C:\wamp\www\bhumi regn\ADAO.php on line 20"
thanks
ADAO.php

<?php
include 'connect.php';
class ADAO
{

public static function registerUsers($users,$dbh){

               try
        {

        }
        catch (PDOException $e) {
            print "Error!: " . $e->getMessage() . "<br/>";
           return false;
        }

        $null="NULL";
        $length=16;

         $stmt=$dbh->prepare("INSERT INTO users values(?,?,?,?,?,?,?,?,?,?,?)");
              $stmt->bindParam(1,$null);
              $stmt->bindParam(2,$users['username']);
              $stmt->bindParam(3,$users['password']);
              $stmt->bindParam(4,$users['fname']);
              $stmt->bindParam(5,$users['lname']);
              $stmt->bindParam(6,$users['email']);
              $stmt->bindParam(7,$users['mobile']);
              $stmt->bindParam(8,$users['phone']);
              $stmt->bindParam(9,$users['address']);
              $stmt->bindParam(11,$users['city']);
              $stmt->bindParam(12,$users['state']);

           $stmt->execute();

           $dbh=null;
           return true;
    }

}
?>

testregisterUser.php

<?php


require_once("ADAO.php");

$obj= new ADAO();

$username="jindal";
$password="jindal";
$fname="test";
$lname="jindal";
$email="jindal@gmail.com";
$mobile="911234567890";
$phone="1234567890";
$address="hsp";
$city="hsp";
$state="punjab";

$obj->registerUsers($username,$password,$fname,$lname,$email,$mobile,$phone,$address,$city,$state);

?>
3
Contributors
6
Replies
31
Views
3 Years
Discussion Span
Last Post by annyangel
1

You defined two parameters in the function. $users and $dbh but you actually sending $username,$password,$fname,$lname,$email,$mobile,$phone,$address,$city,$state in which will cause the wallet of $dbh to be jindal and not a mysqli
Hope I helped

0

WHat elibyy is saying is this:

You're calling the method like this, passing 10 parameters:

$obj->registerUsers($username,$password,$fname,$lname,$email,$mobile,$phone,$address,$city,$state);

But your method only accepts 2 parameters:

public static function registerUsers($users,$dbh)

Meaning that $users will actually be $username (jindal) and $dbh will actually be $password (jindal). So it's messed up.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.