简体   繁体   English

MYSQL更新不能一致地工作

[英]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. 当管理员单击编辑课程时,他可以编辑它们,并且在单击更新时,变量将在mysql数据库中更新。

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."'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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