Hello everyone,

I am confused with these little codes why it keeps error in updating the learner information. These are my codes so far.
These are the bits of Student_Info.php which i think would be useful in my query.

<?php  if(!empty($_GET['flag']) && $_GET['flag'] == "success") { ?>   
        <span class="stylered style1"><span class="style5">Learner Information updated successfully.</span></span>  
        <?php } else if(!empty($_GET['flag']) && $_GET['flag'] == "error") { ?>
        <span class="stylered style3 style5"><span class="style1">Error while updating Learner Information. Please try again</span></span> 
        <?php }  ?>  </td>

This is the Student_Edit_Handler codes.

    $session_id = $_SESSION['user_id'];
    if($session_id == null){
    include 'Connect.php';
    $flag = "";
    $student_id = $_POST['student_id'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $gender = $_POST['gender'];
    $date_of_birth = date("Y-m-d",strtotime($_POST['date_of_birth']));
    $contact_no = $_POST['contact_no'];
    $grade  = $_POST['grade'];
    $section = $_POST['section'];
    $LRN = $_POST['LRN'];
    $email1 = $_POST['email1'];
    $email2 = $_POST['email2'];
    $address = $_POST['address'];
    $description = $_POST['description'];

    $query = "UPDATE student_information SET learner_id='$learner_id',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 .= " WHERE student_id='{$_SESSION['user_id']}'";      
    $result = mysql_query($query, $link_id);
    if(mysql_error() != null){
        if($flag == "success"){
            mysql_query(" COMMIT ");
            if(mysql_error() != null){

It flags the error on else{$flag="error";}

I am stuck with these codes guys, please do help me modify it so learner information will be update.

3 Years
Discussion Span
Last Post by hanspeare_1

Let me give you the hints first...

line 29, 35, and 38 are not valid statements.

Line 36, you've used COMMIT which is the last query segment in trasactional. The BEGIN query should be intiated first and then your update query followed by the COMMIT to finalized the transaction.

IMPORTANT! Transaction only work with the table engine set or equal to innoDB. It will not work on MyISAM.

example of transaction

$this_begin = "BEGIN";
mysql_query($this_begin) or die (mysql_error());

followed by the update query immediately

$this_update = "UPDATE ....";
mysql_query($this_update) or die (mysql_error());

lastly, the commit query

$this_commit = "COMMIT";
mysql_query($this_commit) or die (mysql_error());

there are many ways in setting up statements for this..

    // this is true if the begin query was successfule
        //die or define something as false

If you are lazy like me, this will work also , but THERE IS A BIG BUT.. you need to learn how to do it in the old fashion way first, then you go crazy on the shorthand.

$flag = (mysql_query($this_updatee) ? 'success' : 'error');

Hello veedeoo,

hahaha,, i am so dumb!! Why i haven't think of that....thank you for that hint..

I solve it,,and for the benefit of those future reader on this thread. ill post the solution.

if(mysql_error() != null){


Edited by hanspeare_1: post the solution codes


Congratulations! You're no longer a DaniWeb newbie.<br /> <br />
Your DaniWeb account has just been upgraded from newbie status and now you have the ability to take advantage of everything the community has to offer.<br /> <br />
You can now enjoy an advertisement-free DaniWeb by ticking the checkbox to Disable Ads in your profile. You will no longer have to fill out the human verification check when you post. You can also now send unlimited private messages, participate in live chat, opt-in to mailing list-style notifications which allows you to read and contribute posts via email, contribute new code snippets, and tag articles with never-before-used tags.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.