我正在尝试使用oops.reg方法,但是post方法和javascript函数不起作用。点击注册按钮没有任何反应。 我已经使用dbconnect.php类进行数据库连接。和register.php类来插入数据。
index.php文件:
<html>
<head>
<script type="text/javascript">
function getdata()
{
var name = document.login.name.value;
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
if(name=="" || email=="" || password="")
{
alert("Please Enter data");
}
}
</script>
</head>
<body>
<center>
<form name="login" method="post" action="variable.php" onsubmit="return getdata()">
Name: <input type="text" name="name" id="name"><br><br>
Email: <input type="email" name="email" id="email"><br><br>
Password: <input type="password" name="password" id="passowrd"><br><br>
<input type="button" name="register" value="Register"></input>
</form>
</center>
</body>
</html>
dbconnect.php文件:
class dbconnect{
public function __construct()
{
$con = mysql_connect("localhost:5050","root","");
if(!con)
{
die("Cannot connect database....");
}
mysql_select_db("zenbiz",$con) or die("Error: database not found");
}
}
variable.php文件:
include_once('register.php');
$obj = new register();
if($_POST['register'])
{
$username = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$register = $obj->userRegister($username,$email,$password);
if($register)
{
echo "<script>alert('Registration successfull....')</script>";
}
else{
echo "<script>alert('Not Registered.....')</script>";
}
}
register.php文件:
include_once('dbconnect.php');
class register{
public function __construct()
{
$db = new dbconnect();
}
public function userRegister($name,$email,$password)
{
$query = "INSERT INTO users(username,emailid,password) VALUES ('".$name."','".$email."','".$password."')";
$result = mysql_query($query) or die(mysql_error());
return $result;
}
}