UPDATE查询中有些问题 [英] Something's wrong in UPDATE query

查看:141
本文介绍了UPDATE查询中有些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编辑表单。我为这样的行获取数据 -

  if(isset($ _ GET [id])){ 
$ pur_id = intval($ _ GET [id]);
} else {
echoid not set;
}

然后我试着执行下面的UPDATE查询。 <$ p
$ b

  $ qry1 = mysqli_query($ con,UPDATE`purchase_info` SET`remarks` ='$ remarks'WHERE`pur_info_id` ='$ pur_id'); 

这个查询可以工作,但不会更新数据库中的记录。但它更新记录时,我只是通过数值而不是我将我的行ID的变量。因此,如果我通过'pur_info_id'= 1 那么它更新我的纪录。

这很奇怪。我使用int值转换值,但仍然没有运气。请指教。感谢!!

解决方案

感谢大家分享您宝贵的见解和知识。我找到了解决我的问题的方法。这是一个非常愚蠢的问题,虽然对我来说是新的。我使用_GET请求从表中提取了行ID,然后尝试在我的_POST请求中使用该id,这实际上导致了问题。



我们不能在_POST请求中简单使用_GET的值。因此,解决方案是将_GET的值存储在变量中,并将其保存在隐藏的输入字段中。当做出_POST请求时,我们只需从隐藏字段中取值。再次感谢!!


I have an edit form. I'm fetching the data for the row like this -

if (isset($_GET["id"])) {
    $pur_id = intval($_GET["id"]);
} else {
    echo "id not set";
}

Then I'm trying to execute the following UPDATE query.

$qry1 = mysqli_query($con,"UPDATE `purchase_info` SET `remarks` ='$remarks' WHERE `pur_info_id` = '$pur_id'");

This query does work but it doesn't update the records in my database. But it updates the record when I simply pass numeric value instead of the variable that I'm putting my row ID in. So if I pass 'pur_info_id' = 1 then it updates my record.

It's very odd. I'm converting the value using int value but still no luck. Please advice. Thanks!!

解决方案

Thanks everyone for sharing your valuable insights and knowledge. I've found the solution to my problem. It's a very silly problem, new for me though. I fetched the row id from table using _GET request, and then tried to use the id in my _POST request which actually caused the problem.

We cannot use the values of _GET in _POST request in short. So the solution is to store the value of the _GET in a variable, keep that in a hidden input field. And when the _POST request is made, we simply take the value from the hidden field. Thanks once again!!

这篇关于UPDATE查询中有些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆