I am getting these two errors in this PHP file and I do not know how to fix them.
Object of class mysqli_result could not be converted to int in /afs/http://ift.tt/2oPdOPr on line 73
Catchable fatal error: Object of class mysqli_result could not be converted to string in /afs/http://ift.tt/2oPdOPr on line 84
<?php
include('config.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($db,"SELECT username from Student_Record where username = '$user_check'");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['username'];
if(!isset($_SESSION['login_user'])){
header("location:login.php");
}
if (isset($_POST['task'])) {
$selectOption = $_POST['task'];
}
switch($selectOption)
{
case 2:
{
if (isset($_POST['name'])) {
$name = $_POST['name'];
}
$sql = "SELECT * from Student_Record where fullname = '$name'";
$result=$db->query($sql);
if ($result->num_rows > 0) {
$query = "SELECT grades from Student_Record where fullname = '$name'";
$result1=$db->query($query);
echo "<br><br><table>";
while($row = $result1->fetch_assoc()){
echo "<tr><td>" . $row['grades'] . "</td></tr>";
}
echo "</table>";
}
else{
echo "not found";
}
break;
}
case 1:
{
$selection = $_POST['change'];
$course = $_POST['course'];
$name = $_POST['name'];
$sql = "SELECT courses from Student_Record where fullname = '$name'";
$result = $db->query($sql);
echo "<h1>Before</h1>";
if ($result->num_rows > 0) {
$query = "SELECT courses from Student_Record where fullname = '$name'";
$result1=$db->query($query);
echo "<br><br><table>";
while($row = $result1->fetch_assoc()){
echo "<tr><td>" . $row['courses'] . "</td></tr>";
}
echo "</table>";
}
else{
echo "not found";
}
if($selection="Add"){
$newcourses = $result + $course;
$sql = "UPDATE Student_Record SET courses='$newcourses' WHERE fullname='$name'";
if (mysqli_query($db, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($db);
}
}
if($selection="Drop"){
$newcourses = str_replace($course,"",$result);
$sql = "UPDATE Student_Record SET courses='$newcourses' WHERE fullname='$name'";
if (mysqli_query($db, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($db);
}
}
echo "<h1>Before</h1>";
if ($result->num_rows > 0) {
$query = "SELECT * from Student_Record where fullname = '$name'";
$result1=$db->query($query);
echo "<br><br><table>";
while($row = $result1->fetch_assoc()){
echo "<tr><td>" . $row['fullname'] . "</td><td>" . $row['Student_ID'] . "</td><td>" . $row['email'] . "</td><td>" . $row['courses'] . "</td><td>" . $row['grades'] . "</td></tr>";
}
echo "</table>";
}
else{
echo "not found";
}
break;
}
default:
{
echo("Error!");
exit();
break;
}
}
$checkQuery = "SELECT * from Student_Record WHERE
fullname='$_POST[name]'";
$userCheck = mysqli_query($db, $checkQuery);
if(!$userCheck){
echo "Invalid name";
return false;
}
$checkQuery = "SELECT * from Student_Record WHERE
Student_ID='$_POST[studentid]'";
$userCheck = mysqli_query($db, $checkQuery);
if(!$userCheck){
echo "Invalid Student ID";
return false;
}
?>
Aucun commentaire:
Enregistrer un commentaire