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
Post
by jonnyfortis » Fri Jan 16, 2015 7:51 am
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());
?>
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 8:19 am
jonnyfortis wrote: my sql is not working
How is it not working? What's happening? What errors are you getting?
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 8:20 am
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.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 8:21 am
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
Post
by jonnyfortis » Fri Jan 16, 2015 8:25 am
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
still not updating
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Jan 16, 2015 8:26 am
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'
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 8:37 am
Have you checked the value of $query? What about mysql_error()?
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Jan 16, 2015 9:28 am
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
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 9:39 am
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
Post
by jonnyfortis » Fri Jan 16, 2015 9:46 am
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())
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 9:48 am
Can you post the entire script?
jonnyfortis
Forum Contributor
Posts: 462 Joined: Tue Jan 10, 2012 6:05 am
Post
by jonnyfortis » Fri Jan 16, 2015 9:55 am
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
?>
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 9:56 am
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
Post
by jonnyfortis » Fri Jan 16, 2015 10:03 am
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
obviously because of the brackets
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Fri Jan 16, 2015 10:11 am
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
is not a valid statement. You need
Code: Select all
$result=mysql_query($query) or die(mysql_error());