laserlight;10901684 wrote:The implication is that the SQL statement failed to execute and thus $result contains a boolean false value. Check the database server connection, that the correct database was selected, and that the SQL statement is correct.
here is my include/user_auth_fns.php and include/db_fns.php
whole page.php
<?php
require_once('include/session.php');
require_once('include/user_auth_fns.php');
$cur_login = $_SESSION["username"];
$conn= db_connect();
$aa=0;
$query = "SELECT mm.mentee, mm.username_mentee, mp.major ".
"FROM mentormentee mm LEFT JOIN mentee_personal_details mp ".
"ON mp.mentee_id = mm.username_mentee".
"WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee";
$result = $conn->query($query);
$query1 = "select major from mentee_personal_details where mentee_id = '$m'";
?>
<?php
while ($row = mysqli_fetch_assoc($result)){
$aa = $aa + 1;
?>
<td><?php echo $aa; ?> </td>
<td><?php echo $row['mentee']; ?> </td>
<td><?php echo $row['username_mentee']; ?> </td>
<td><?php echo $row['major']; ?> </td>
</tr><?php } ?>
</body>
</html>
include/user_auth_fns.php
<?php
require_once('db_fns.php');
function register($name, $username, $password, $userlevel, $department, $status, $nationality)
// register new person with db
// return true or error message
{
// connect to db
$conn = db_connect();
// check if username is unique
$result = $conn->query("select * from user where username='$username'");
if (!$result)
throw new Exception('Could not execute query');
if ($result->num_rows>0)
throw new Exception('That username is taken - go back and choose another one.');
// if ok, put in db
$result = $conn->query("insert into user (name, username, password, userlevel, department, status, nationality) values ('$name', '$username', sha1('$password'), '$userlevel', '$department', '$status', '$nationality')");
if ($userlevel==4){
$conn->query("insert into mentormentee (mentor, username_mentor, mentee, username_mentee) values ('','','$name', '$username')");
$conn->query("insert into mentee_personal_details (mentee_id, fullname, postal_address1, postal_address2, postal_address3, postal_zip, post_telephone, degree, major, race, marital_status, hobbies, permanent_address1, permanent_address2, permanent_address3, per_zip, per_telephone) values ('$username','$name','', '', '', '', '', '', '', '', '', '', '', '', '', '', '')");
$conn->query("insert into family_details (mentee_id, family_membername, relationship, occupation) values ('$username', '', '', '')");
$conn->query("insert into results ('mentee_id', 'spm_stpm_school', 'spm_stpm_year1', 'spm_stpm_certificate', 'spm_stpm_year2', 'dip_deg_school', 'dip_deg_school_year1', 'dip_deg_school_certificate', 'dip_deg_school_year2') values ('$username', '', '', '', '', '', '', '', '')");
$conn->query("insert into curiculum ('mentee_id', 'co_activity, co_post, co_year') values ('$username', '', '', '')");
$conn->query("insert into semester_system (mentee_id, gpa, cgpa, semester_no, code, subject, credit_hour, grade) values ('$username', '', '', '', '', '', '', '')");
}
if ($userlevel==2 OR 3){
$conn->query("insert into mentor_personal_details (staff_id, fullname, postal_address1, postal_address2, postal_address3, postal_zip, post_telephone, degree, race, marital_status, permanent_address1, permanent_address2, permanent_address3, per_zip, per_telephone) values ('$username','$name','', '', '', '', '', '', '', '', '', '', '', '', '')");
}
if (!$result)
throw new Exception('Could not register in database - please try again later.');
return true;
}
//test function
function test($nama, $id, $course, $intake){
//connect database
$conn = cdb_connect();
$result3 = $conn->query("insert into user(nama, id, course, intake) values ('$nama', '$id', '$course', '$intake')");
if($result3){ ?>
<SCRIPT LANGUAGE="Javascript">
alert('The data successfully UPDATE!');
</SCRIPT> <?php
}else{ ?>
<SCRIPT LANGUAGE="Javascript">
alert('The data cannot be UPDATE!');
</SCRIPT> <?php
}
}
function add_profile($staff_id, $fullname, $postal_address1, $postal_address2, $postal_address3, $postal_zip, $post_telephone, $degree, $race, $marital_status,
$permanent_address1, $permanent_address2, $permanent_address3, $per_zip, $per_telephone){
//connect database
$conn = db_connect();
if (!$result1){
throw new Exception('Could not add in database - please try again later.');
}
return true;
}
function check_valid_user()
// see if somebody is logged in and notify them if not
{
if (isset($_SESSION['username']))
return true;
else
return false;
}
?>
db_fns.php
<?php
function db_connect()
{
$result = new mysqli('localhost', 'root', '', 'rama1');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}
?>
the error is:
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\nrsh\all.php on line 150