简体   繁体   中英

MYSQL Update doesn't work consistently

I have included in my back end a table that populates a list of courses. When an admin clicks edit course, he is able to edit them, and upon clicking update the variables are updated in the mysql database.

The problem is that the update does seem to work with all courses, where the courses information are nearly identical. it seems to only work half of the time. I was wondering if there was a work around the following:

<?php

//getting the text data from the fields
    if(isset($_POST['update_course'])) {
        $update_id          =   $pro_id;
        $course_provider    =   $_POST['course_provider'];
        $course_price       =   $_POST['course_price'];
        $course_desc        =   $_POST['course_desc'];
        $course_sdesc       =   $_POST['course_sdesc'];
        $course_editor      =   $_POST['course_editor'];
        $course_prereq      =   $_POST['course_prereq'];
        $course_tax         =   $_POST['course_tax'];

        $update_course      =   "update courses set course_updated='<b>$course_editor</b>', course_priceFinal=$course_tax*$course_price, course_tax='$course_tax', course_prereq='$course_prereq', course_sdesc='$course_sdesc'
        where course_id2 ='$update_id'";
        $run_course = mysqli_query($con, $update_course);

        if($run_course) {
            echo "<script>window.open('index.php?view_course','_self')</script>";
        }
        else {
            echo "<script>window.open('index.php?view_course','_self')</script>";
        }
    } ?>

I a greatly appreciate any help.

Try changing your statement to:

$update_course = update courses set course_updated='".$course_editor."',
course_priceFinal='".$course_tax*$course_price."', 
course_tax='".$course_tax."', course_prereq='".$course_prereq."', 
course_sdesc='".$course_sdesc."' where course_id2 ='".$update_id."'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM