伙计们,这是我写的代码。我有两份文件。
一号文件。
$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;在上面的代码中,我从表单a中获取变量并存储它们。然后,我实例化一个对象,并将所有这些对象传递给一个方法。
我的类代码id是这样的。
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";
}
}我得到一个错误,如‘字段列表’中的未知列'john‘。新的OOPS请提前help...Thnx .....
发布于 2013-05-29 15:57:28
现在试一试。这是一个与OOPS无关的错误,只是数据库方面的问题。
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";
}
}发布于 2013-05-29 15:57:38
这是因为您在SQL查询值中使用了反引号。您需要使用撇号而不是反号,否则查询将认为您引用了另一列,在本例中为'john‘。
更改:
INSERT INTO onlinereg (names,sid,emails,mobiles) VALUES (`$regname`,`$sponserid`,`$regemail`,`$regmobile`)至:
INSERT INTO onlinereg (names,sid,emails,mobiles) VALUES ('$regname','$sponserid','$regemail','$regmobile')发布于 2013-05-29 16:04:33
简单的改变
`name`对于'name',您使用的是错误的引号。这个问题实际上与面向对象编程无关。
https://stackoverflow.com/questions/16808336
复制相似问题