After working with procedural code for quite a while now i decided to try and take the plunge into OOP PHP ,I am really new to OOP PHP so please take it easy on me if this isnt valid OOP yet....
The index.php page. I have stripped the body,head tags for miminal post
Code: Select all
<?php
include_once('includes/connectionclass.php');
$connect = new Connections();
$connect -> EstablishConnection();
include_once("includes/userclass.php");
if (isset($_POST['login'])){
$NewUser = new User();
$loginerror = $NewUser->authorise();
}
?>
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"> </td>
<td width="73%"> </td>
</tr>
<tr>
<td colspan="2" class="centredfonts">Username</td>
<td><input name="username" type="text" class="inputs" id="username" /></td>
</tr>
<tr>
<td colspan="2" class="centredfonts">Password</td>
<td><label>
<input type="password" name="password" id="password" class="inputs" />
</label></td>
</tr>
<tr>
<td colspan="2"> </td>
<td><label>
<input type="submit" name="login" id="login" value="Login" />
</label></td>
</tr>
<tr>
<td colspan="2"> </td>
<td> </td>
</tr>
<tr>
<td width="9%"> </td>
<td colspan="2" class="loginerror"><?php echo $loginerror;?></td>
</tr>
</table>
</form>The function/method inside userclass.php
Code: Select all
function authorise(){
$this->username = $_POST['username'];
$this->password = $_POST['password'];
$sql = "SELECT `username`,`password` from `users` WHERE `username` = '".$this->username."'";
$query = mysql_query($sql);
$result = mysql_num_rows($query);
if ($result == 0){
print "You dont seem to be registered.";
}else{
$UserArray = mysql_fetch_array($query);
//check password
if ($UserArray['password'] != $this->password){
$this->loginerror = "Incorrect Username/Password";
echo $this->loginerror;
}else{
$this->loginerror = "Login Correct";
echo $this->loginerror;
}
}like this ?
Code: Select all
<?php
if ($loginerror != ""){
echo "The value returned is different to nothing";
}
Regards Shab