update sql not updating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

update sql not updating

Post 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());


?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post by Celauran »

jonnyfortis wrote:my sql is not working
How is it not working? What's happening? What errors are you getting?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post 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?
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post 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
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post 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'
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post by Celauran »

Have you checked the value of $query? What about mysql_error()?
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post by Celauran »

i commented out the mysql_error()
Uncomment it and see what the error is.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post 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())
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post by Celauran »

Can you post the entire script?
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post 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

?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post 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.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: update sql not updating

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: update sql not updating

Post 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());
Post Reply