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);

?>
Member Avatar for diafol

Why do you want to create a manual registration script without an user using a form?

for the testing purpose

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

thanks... but its not sufficient for me bcoz i m a starter

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.