Page 1 of 2

update sql not updating

Posted: Fri Jan 16, 2015 7:51 am
by jonnyfortis
if an order is cancelled i need it to update the database but my sql is not working, can someone have a look at it for me please?

Code: Select all

<?php
session_start();

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$orderID = $_SESSION['OrderID'];

mysql_select_db($database_wiz, $wiz);
$query_rsReturn = "SELECT * FROM wiz_orders WHERE wiz_orders.OrderID = '$orderID'";
$rsReturn = mysql_query($query_rsReturn, $wiz) or die(mysql_error());
$row_rsReturn = mysql_fetch_assoc($rsReturn);
$totalRows_rsReturn = mysql_num_rows($rsReturn);

{
$query="UPDATE wiz_orders SET TransactResult = 'cancelled by customer' WHERE wiz_orders.OrderID = '$orderID'";
}

$result=mysql_query($query)
//or die(mysql_error());


?>

Re: update sql not updating

Posted: Fri Jan 16, 2015 8:19 am
by Celauran
jonnyfortis wrote:my sql is not working
How is it not working? What's happening? What errors are you getting?

Re: update sql not updating

Posted: Fri Jan 16, 2015 8:20 am
by Celauran

Code: Select all

{
$query="UPDATE wiz_orders SET TransactResult = 'cancelled by customer' WHERE wiz_orders.OrderID = '$orderID'";
}
What's going on here? Looks like there's a conditional missing. Those braces just sitting there by themselves aren't right.

Re: update sql not updating

Posted: Fri Jan 16, 2015 8:21 am
by Celauran

Code: Select all

 $result=mysql_query($query)
Missing semicolon at the end of this line also. Does your editor not point these things out?

Re: update sql not updating

Posted: Fri Jan 16, 2015 8:25 am
by jonnyfortis
Celauran wrote:

Code: Select all

{
$query="UPDATE wiz_orders SET TransactResult = 'cancelled by customer' WHERE wiz_orders.OrderID = '$orderID'";
}
What's going on here? Looks like there's a conditional missing. Those braces just sitting there by themselves aren't right.
yes i have removied the braces as there should not be any conditions as this page is just for cancelled orders i also added ; to the

Code: Select all

$result=mysql_query($query);
still not updating

Re: update sql not updating

Posted: Fri Jan 16, 2015 8:26 am
by jonnyfortis
Celauran wrote:
jonnyfortis wrote:my sql is not working
How is it not working? What's happening? What errors are you getting?
no errors just not sending the 'cancelled by customer'

Re: update sql not updating

Posted: Fri Jan 16, 2015 8:37 am
by Celauran
Have you checked the value of $query? What about mysql_error()?

Re: update sql not updating

Posted: Fri Jan 16, 2015 9:28 am
by jonnyfortis
Celauran wrote:Have you checked the value of $query? What about mysql_error()?
i just echo out the $query after processing and order and got the following

UPDATE bwiz_orders SET TransactResult = 'cancelled by customer' WHERE wiz_orders.OrderID = '5411'
i commented out the mysql_error() because i wanted to use the order id later down the page

Re: update sql not updating

Posted: Fri Jan 16, 2015 9:39 am
by Celauran
i commented out the mysql_error()
Uncomment it and see what the error is.

Re: update sql not updating

Posted: Fri Jan 16, 2015 9:46 am
by jonnyfortis
Celauran wrote:
i commented out the mysql_error()
Uncomment it and see what the error is.
Parse error: syntax error, unexpected T_LOGICAL_OR in E:\Domains\b\wizzy.com\user\htdocs\SS15cancel.php on line 49

line 49 is or die(mysql_error())

Re: update sql not updating

Posted: Fri Jan 16, 2015 9:48 am
by Celauran
Can you post the entire script?

Re: update sql not updating

Posted: Fri Jan 16, 2015 9:55 am
by jonnyfortis
Celauran wrote:Can you post the entire script?

Code: Select all

<?php require_once('Connections/wizSS15.php'); ?>
<?php
session_start();

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$orderID = $_SESSION['OrderID'];

mysql_select_db($database_wizSS15, $wizSS15);
$query_rsReturn = "SELECT * FROM wiz_orders WHERE wiz_orders.OrderID = '$orderID'";
$rsReturn = mysql_query($query_rsReturn, $wizSS15) or die(mysql_error());
$row_rsReturn = mysql_fetch_assoc($rsReturn);
$totalRows_rsReturn = mysql_num_rows($rsReturn);

//////////////////////

$query="UPDATE wiz_orders SET TransactResult = 'cancelled by customer' WHERE wiz_orders.OrderID = '$orderID'";

$result=mysql_query($query);
or die(mysql_error());

//////////////////////

echo $query;
?>
then in the body

Code: Select all

<p>You have cancelled your order <?php echo $orderID ; ?></p>
then at the end of the page

Code: Select all

<?php
mysql_free_result($rsReturn);

session_unregister("OrderID"); // killed

?>

Re: update sql not updating

Posted: Fri Jan 16, 2015 9:56 am
by Celauran

Code: Select all

$result=mysql_query($query);
or die(mysql_error());
You needed the ; after mysql_query() when the next line was commented out. Now you need to put it back.

Re: update sql not updating

Posted: Fri Jan 16, 2015 10:03 am
by jonnyfortis
Celauran wrote:

Code: Select all

$result=mysql_query($query);
or die(mysql_error());
You needed the ; after mysql_query() when the next line was commented out. Now you need to put it back.
like this??

Code: Select all

$result=mysql_query($query);
or die(mysql_error());
the trouble is im getting a code hint with

Code: Select all

or die(mysql_error());
obviously because of the brackets

Re: update sql not updating

Posted: Fri Jan 16, 2015 10:11 am
by Celauran
jonnyfortis wrote:
Celauran wrote:

Code: Select all

$result=mysql_query($query);
or die(mysql_error());
You needed the ; after mysql_query() when the next line was commented out. Now you need to put it back.
like this??
No. You're getting the error because

Code: Select all

or die(mysql_error());
is not a valid statement. You need

Code: Select all

$result=mysql_query($query) or die(mysql_error());