1

Guys this is a code i have written. I have two files.

File one.

$regname=$_POST['name']; -----> here the variable passed is john suppose.. 
$sponserid=$_POST['sname'];   
$regemail=$_POST['email'];
$regmobile=$_POST['mobile'];
include 'dbcon.php';
$obj = new dbcon;  
$obj->createUser($regname,$sponserid,$regemail,$regmobile); 
echo $obj;

in the above code i am getting variables from a form a and storing them. Then I instantiate an object and pass all those to a method.

My class code id like this.

class dbcon
{
  public function __construct() //This is the connection construct.
{

        $server = "localhost";
        $user = "eplu";
        $pass = "123456"; //Change on hosting server
        $db = "epl";
        mysql_connect($server, $user, $pass) or die("Error connecting to sql server: ".mysql_error());
        mysql_select_db($db);
        }


public function createUser($regname,$sponserid,$regemail,$regmobile){
        $sql = "INSERT INTO onlinereg (names,sid,emails,mobiles) VALUES (`$regname`,`$sponserid`,`$regemail`,`$regmobile`)";
        mysql_query($sql) or die(mysql_error());
        return "Registration Success";
        }

}

I get an error like Unknown column 'john' in 'field list'. New to OOPS pls help...Thnx in advance.....

2

3 Answers 3

3

Try now. This is not an OOPS related error, just the database thing.

class dbcon
{
  public function __construct() //This is the connection construct.
{

        $server = "localhost";
        $user = "eplu";
        $pass = "123456"; //Change on hosting server
        $db = "epl";
        mysql_connect($server, $user, $pass) or die("Error connecting to sql server: ".mysql_error());
        mysql_select_db($db);
        }


public function createUser($regname,$sponserid,$regemail,$regmobile){
        $sql = "INSERT INTO onlinereg (names,sid,emails,mobiles) VALUES ('$regname','$sponserid','$regemail','$regmobile')";
        mysql_query($sql) or die(mysql_error());
        return "Registration Success";
        }

}
2

Its because you are using backticks in your SQL query values. You need to use apostrophes instead of backticks, else the query will think you are referencing another column, in this case, 'john'

Change:

 INSERT INTO onlinereg (names,sid,emails,mobiles) VALUES (`$regname`,`$sponserid`,`$regemail`,`$regmobile`)

to:

INSERT INTO onlinereg (names,sid,emails,mobiles) VALUES ('$regname','$sponserid','$regemail','$regmobile')
2
  • I tried the quotes now i get these errors. Missing argument 1 for dbcon::createUser(), called in C:\wamp\www\backup\process\dbcon.php on line 24 and defined in C:\wamp\www\backup\process\dbcon.php on line 17
    – DarthVader
    Commented May 29, 2013 at 8:09
  • Thats a completely different problem. I would suggest updating your original question. Also, make sure you are actually passing a value to $regname, IE make sure $_POST['name'] isn't empty.
    – Phil Cross
    Commented May 29, 2013 at 8:13
0

Simple change

`name`

to 'name' You are using wrong quotes. This question is not really related to OOP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.