1

PHP usually works pretty much straight out of the box, but I cannot get this query to work. 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.

2
  • There are no error messages showing from mysql, however I'm not sure how to use the echo method to check?? Commented Sep 6, 2012 at 9:46
  • Always in these cases: echo out your query and copy-and-paste it into a database session (MySQL on the console, or phpMyAdmin). As others have pointed out, you have an error in your SQL. Commented Sep 6, 2012 at 9:48

4 Answers 4

4

I wonder if u have tried to print_r your $query to check.

1st. Shift your connection string to the top most.

2nd. status=$status' <<=== less 1 quote

Sign up to request clarification or add additional context in comments.

Comments

3

I thought you had to connect to the database before you were able to use mysql_real_escape_string()? Try connecting above all other code.

The status section of the query is also missing a quote mark.

4 Comments

You're right. You can't use mysql_real_escape_string without a valid connection.
I have pushed the connection to the top of the code, however the same error occurs....
echo $query and paste it into phpmyadmin to see what it tells you.
Got it sorted, apparently I named one of my columns incorrectly.... no wonder no one here spoted it. Thanks everyone for your help anyhow.... so glad I got this sorted :)
1

Try changing by adding a comma

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

And FYI change paid='paid' to paid='$paid' to ensure the correct value is passed

Comments

1

Your error is because of not handling your status update correctly: status=$status' must be status='$status'.

You would have figured this if you'd put a mysql_error() in your 'fail' section.

1 Comment

I have changed the status problem with no avail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.