dtry54612 2016-03-07 16:07
浏览 21

如何更新表中的值

I cannot update the values in my table with this code, if the update is successful the page should redirect in ('Location:ui.php'), how can this be achieved?

<?php
ob_start();
include('dbconnect.php');

$code=$_GET['stallcode'];

if(isset($_POST['submit']))
{
    $pcost = $_POST['pcost'];
    $tcost = $_POST['tcost'];
    $cash = $_POST['cash'];
    $change = $_POST['change'];
    if (($cash == '0')) 
    {
        $pstatus="0";
    }
    else
    {
        $pstatus="1";
    }

    $updated=mysql_query("UPDATE tbl_stallowner SET 
            paymentstatus='$pstatus', penaltycost='$pcost',        totalcost='$tcost', cash='$cash', change='$change' 
            WHERE stallcode='$code'")or die();
    if($updated)
    {
        $msg="Successfully Updated!!";
        header('Location:ui.php');
    }
}  //update ends here

ob_end_flush();
?>
  • 写回答

2条回答 默认 最新

  • doubao12345 2016-03-07 16:24
    关注

    As you redirects users by checking if($updated) is true, this will not work, you should check the number of affected rows instead using mysql_num_rows.

    Also remember to exit; after header() to stop the execution.

    $num_rows = mysql_num_rows($updated);
    if($num_rows > 0)
    {
    $msg="Successfully Updated!!";
    header('Location:ui.php');
    exit;
    }
    

    Tip: You should not be using MySQL as it has already been deprecated, use MySQLi instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题