简体   繁体   English

更新查询在MySQL和PHP中不起作用

[英]Update query in MySQL and PHP not working

PHP usually works pretty much straight out of the box, but I cannot get this query to work. PHP通常可以直接使用,但是我无法使该查询正常工作。 I am attempting to update a simple record. 我正在尝试更新一个简单的记录。 My code is as follows. 我的代码如下。

<?php

 $customername=mysql_real_escape_string($_POST['customername']); 
 $contact=mysql_real_escape_string($_POST['contact']); 
 $customerorder=mysql_real_escape_string($_POST['customerorder']); 
 $orderplaced=mysql_real_escape_string($_POST['orderplaced']); 
 $staffmember=mysql_real_escape_string($_POST['staffmember']); 
 $daterequired=mysql_real_escape_string($_POST['daterequired']); 
 $status=mysql_real_escape_string($_POST['status']); 
 $paid=mysql_real_escape_string($_POST['paid']); 
 $delivery=mysql_real_escape_string($_POST['delivery']); 
 $ordercontent=mysql_real_escape_string($_POST['ordercontent']); 
 $orderid=mysql_real_escape_string($_GET['orderid']); 

mysql_connect("localhost", "xxxx", "xxxxxxx") or die("Connection Failed");
mysql_select_db("xxxxxx")or die("Connection Failed");


$query = "UPDATE ordermanager_orders SET customername='$customername', contact='$contact',  ordernumber='$customerorder', placedby='$orderplaced', requiredby='$daterequired', status=$status', staffmember='$staffmember', paid='paid', delivery='$delivery', ordercontent='$ordercontent' WHERE order='$orderid'";

if(mysql_query($query)){
 echo "updated";}
 else{
 echo "fail";}

?> 

The values are being posted or "Getted" from another page. 这些值正在从另一个页面发布或“获取”。 They are definitely coming through as otherwise it comes up with errors. 它们肯定会通过,否则会出现错误。 At the moment it simply comes up with 'failed' as per the code. 目前,它只是根据代码提出“失败”。

I have tried numerous variants of code found on the internet, to check if my coding was correct, however I still cannot get it to work. 我尝试了多种在Internet上找到的代码变体,以检查我的编码是否正确,但是仍然无法正常工作。

I wonder if u have tried to print_r your $query to check. 我想知道您是否尝试过print_r您的$ query进行检查。

1st. 1号 Shift your connection string to the top most. 将您的连接字符串移到最顶部。

2nd. 2号 status=$status' <<=== less 1 quote status=$status' << ===减去1个引号

I thought you had to connect to the database before you were able to use mysql_real_escape_string() ? 我以为您必须先连接到数据库,然后才能使用mysql_real_escape_string() Try connecting above all other code. 尝试在所有其他代码上方进行连接。

The status section of the query is also missing a quote mark. 查询的状态部分也缺少引号。

Your error is because of not handling your status update correctly: status=$status' must be status='$status' . 您的错误是因为未正确处理status更新: status=$status'必须为status='$status'

You would have figured this if you'd put a mysql_error() in your 'fail' section. 如果将mysql_error()放在“ fail”部分中,您将发现这一点。

Try changing by adding a comma 尝试通过添加逗号进行更改

status=$status' to status='$status' status=$status'status='$status'

And FYI change paid='paid' to paid='$paid' to ensure the correct value is passed 为了确保传递正确的值,FYI将paid='paid'更改为paid='$paid'

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

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