Outputting message in middle of page from class.
Posted: Fri May 22, 2009 7:18 am
Hi guys i have a small problem, Im wishing to print out a message halfway through the html page, The connection class and user class is working fine i mean its returning the messages to the index.php page but its just outputting them at the top of the page.
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
As you can see im trying to print out the returned value from $NewUser->authorise method here
The function/method inside userclass.php
Also how would i go about conditioning the returned value from the method in the index.php page?
like this ?
Sorry for the long post and thank you to all who take the time out to read it and reply 
Regards Shab
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