-1

First of all I would like to accept my fault for loading the tables with many columns. I plan to separate it after I solve this issue. I wrote the code Admin_Edit_Info.php as shown below but I failed to update the data. I've been figuring these out for few days. Considering the codes are not that complicated, I really thought that this would be easy but I got a problem in updating the table.

    $query = "UPDATE student_information SET first_name='$first_name',last_name='$last_name',";    
$query .= "gender='$gender',date_of_birth='$date_of_birth',contact_no='$contact_no',grade='$grade',section='$section',";
$query .= "LRN='$LRN',email1='$email1',email2='$email2',address='$address',description='$description',"; 
$query .= "Fil1='$Fil1',Fil2='$Fil2',Fil3='$Fil3',Fil4='$Fil4',Eng1='$Eng1',Eng2='$Eng2',Eng3='$Eng3',Eng4='$Eng4',";
$query .= "Mat1='$Mat1',Mat2='$Mat2',Mat3='$Mat3',Mat4='$Mat4',Sci1='$Sci1',Sci2='$Sci2',Sci3='$Sci3',Sci4='$Sci4',";
$query .= "Ap1='$Ap1',Ap2='$Ap2',Ap3='$Ap3',Ap4='$Ap4',Tle1='$Tle1',Tle2='$Tle2',Tle3='$Tle3',Tle4='$Tle4',";
$query .= "Mus1='$Mus1',Mus2='$Mus2',Mus3='$Mus3',Mus4='$Mus4',Art1='$Art1',Art2='$Art2',Art3='$Art3',Art4='$Art4',";
$query .= "Pe1='$Pe1',Pe2='$Pe2',Pe3='$Pe3',Pe4='$Pe4',H1='$H1',H2='$H2',H3='$H3',H4='$H4',Esp1='$Esp1',Esp2='$Esp2',Esp3='$Esp3',Esp4='$Esp4'";  
$query .= " WHERE student_id='$student_id'";      
$result = mysqli_query($query, $link_id);
if(mysqli_error() != null){
    $recordUpdated = true;
}
else
{
    $recordUpdated = false;
}
header("location:Admin_Home.php?flag=$flag&student_id=$student_id&status=1");
?>

I am maybe you also need the configuration so I am including it here.

Connection.php

<?php
$host = "localhost";
$dbusername = "root";
$dbpassword = "765632";
$dbname = "student";
$link_id = mysqli_connect($host,$dbusername,$dbpassword,$dbname) or die("Error " . mysqli_error($link_id)); 
?>

Just in case I have a mismatch in my configuration.

CodeNewbie
  • 1,665
  • 14
  • 27
user3481449
  • 13
  • 1
  • 5

2 Answers2

1

This line:

$result = mysqli_query($query, $link_id);

$link_id being your DB connection, the connection variable must go first.

$result = mysqli_query($link_id, $query);

Having error reporting on and adding it to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1);
as well as or die(mysqli_error($link_id)) to mysqli_query() would have signaled the error.

Plus if(mysqli_error() != null){...} could probably be changed to if($result){...}


Your present code is open to SQL injection. Use prepared statements, or PDO with prepared statements, they're safer.

Community
  • 1
  • 1
Funk Forty Niner
  • 73,764
  • 15
  • 63
  • 131
  • Your first advise solve my current issues. This is what i missed in trying to solve this issue before. I lack that basics on the manual, maybe for sometime i need to read your link to improve my knowledge. By the way, in this case although i already put that error reporting it displays no error. But I am more interested on your final comment about changing `if(mysqli_error() != null){...}` to `if($result){...}' What does it mean and the advantage of having it? – user3481449 Sep 10 '14 at 02:21
  • `!= null` and `if($result)` both do the same thing. Is not null and if results react the same way, it's just interpreted differently. I've never used `!=null` as doing `if($result)` for me, is checking to see if it's "positive" first, then if not, carry it over to possible errors. @user3481449 – Funk Forty Niner Sep 10 '14 at 02:24
  • Well, thanks for that additional info, i'm on the level of collecting essential knowledge. @Fred -ii- – user3481449 Sep 11 '14 at 02:24
0

Change this line from:

<br/>

if(mysqli_error() != null){
$recordUpdated = true;
}
<br/>

to:

if(mysqli_error() == null){
$recordUpdated = true;
}
Jad
  • 473
  • 2
  • 10
  • 23
Ramesh Singh
  • 88
  • 1
  • 14
  • I followed your advise and have same effect with my previous one but probably your advise is better than my previous code. if it is okay for you may i know how it differs from my previous code? – user3481449 Sep 10 '14 at 02:10