Thanks. I would like to let user login , And i try to do it in oop way
Here is the loginPage.php
<html>
<body>
<?php require_once("connection.php");
$instance=new connection("527442_1","chi1234a","foodil_zxq_1");
if (isset($_POST['s'])) {
$SecIns=new login($_POST['u'],$_POST['p']);
echo $SecIns->enter();
}
?>
<form name="fm" method="POST" action="show.php">
User Name :<input type="text" name="u">
<br>
Password: <input type="password" name="p">
<br>
<input type="submit" name="s">
</form>
</body>
</html>
Here is the oop code which i fail Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
<?php
class connection
{var $user;
var $pass;
var $db;
function __construct($user,$pass,$db){
$this->user=$user;
$this->pass=$pass;
$this->db=$db;
}
function conn(){
$conn=mysql_connect('localhost' , $this->user , $this->pass) or die ("Can't connect server");
mysql_select_db($this->db,$conn) or die ("DB error");
}
}
class login extends connection
{
function __construct($id,$pwd)
{$this->id=$id;
$this->pwd=$pwd;
}
function enter()
{$this->query="SELECT * FROM test WHERE id='".$this->id."' AND pwd='". $this->pwd."';";
$result=mysql_query($this->query,$this->conn) or die ("Error:" . mysql_error());
if (mysql_num_rows($this->result)<1)
return "Not correct user";
else
return "Login success";
}
}
?>
The problem is at the function enter()
.Should be the format problem?? But i spend a long time on it . Thanks.