PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
proc.php
<?php
session_start();
class SQL {
function login ($username,$password) {
$this->username = strip_tags($username);
$this->password = strip_tags($password);
$this->password = md5($this->password);
$this->sql = "SELECT `*` FROM `teachers` WHERE `username`= $this->username AND `password`= $this->password";
$this->query = mysql_query($this->sql);
$this->result = mysql_num_rows($this->query);
if ($this->result === 1) {
//user has been found in the database,lets continue.
$_SESSION['valid'] = 'TRUE';
$_SESSION['user'] = $this->username;
return 'pass';
}
else {
//user was not found in the admin table
return 'fail';
}
}//end of login
function students ($username) {
$this->query = "SELECT `*` FROM students WHERE `teacher`= $username";
$this->run = mysql_query($this->query);
}
}
index.php
<?php
session_start();
$username = $_SESSION['user'];
include("proc.php");
$get = new SQL;
echo <<<WEL
Welcome to your personal administration panel $username.
You can use this panel to manage all the grades of the students.
WEL;
while ($get->students()) = mysql_fetch_assoc($get->students->run) {
}
im trying classes and the problem i get is Parsing Error: syntax error, unexpected '=' (line 11) for index.php.wats the problems?
$this->sql = "SELECT `*` FROM `teachers` WHERE `username`= $this->username AND `password`= $this->password";
$this->query = mysql_query($this->sql);
//BUT
$this->query = "SELECT `*` FROM students WHERE `teacher`= $username";
$this->run = mysql_query($this->query);
The line with while is a bit of a mess in more than one way, rethink what you are doing.
while ($get->students()) = mysql_fetch_assoc($get->students->run) {
Not sure what you are trying to do, probably a getStudents($teacher) method would make sense in the class. Also, "SQL" is a terrible name. This is a Model class, so I would call it TeacherModel or CourseModel or something descriptive.
all right all thanks. the thing is,i jus started with classes so im new to them,i was trying to follow the manual-.- and got alittle lost. wat i was trying to do with that while statment was to make a table out of it dsiplaying the data i wanted to show from my db