Page 1 of 1

[Solved] Passing 2 arguments in URL help

Posted: Mon Jul 16, 2007 8:45 am
by Addos
Hi,
I’m not sure how to pass two arguments to my query using the following:

Code: Select all

<a href="paybycheque.php?order_ID=<?php echo($row_rsCWOrder["order_ID"]);?>&cst_ID=<?php echo($row_rsCWOrder["order_CustomerID"]);?>">Change</a>
And this is where I’m passing this to but I’m getting and error.
Can anyone tell/show me what I need to do?
Thanks
B

Code: Select all

<?php
$colname_GetCustomer = "1";
if (isset($_GET['cst_ID'])) {
  $colname_GetCustomer = (get_magic_quotes_gpc()) ? $_GET['cst_ID'] : addslashes($_GET['cst_ID']);
}
mysql_select_db($database_*****, $*****);
$query_GetCustomer = sprintf("SELECT * FROM tbl_customers, tbl_orders
WHERE order_ID = '%s'
AND cst_ID = '%s'", $colname_GetCustomer);
$GetCustomer = mysql_query($query_GetCustomer, $batchelors) or die(mysql_error());
$row_GetCustomer = mysql_fetch_assoc($GetCustomer);
$totalRows_GetCustomer = mysql_num_rows($GetCustomer);
?>

Posted: Mon Jul 16, 2007 8:52 am
by Begby
And the error is?

Posted: Mon Jul 16, 2007 9:21 am
by boo
I dont see where you are passing order_ID into the SQL statement.

Here you are getting the cst_id value but you are not doing the same for the order_ID

Code: Select all

$colname_GetCustomer = "1"; 
if (isset($_GET['cst_ID'])) { 
  $colname_GetCustomer = (get_magic_quotes_gpc()) ? $_GET['cst_ID'] : addslashes($_GET['cst_ID']); 
}

Posted: Mon Jul 16, 2007 10:33 am
by Addos
"I dont see where you are passing order_ID into the SQL statement."

Yep that's where I'm stuck as i know only how to pass one value and not the two together.

Thanks for your reply.
B

Posted: Mon Jul 16, 2007 12:07 pm
by dxm
You can get and check both the variables passed through the URL like this, then it's just adding it to your query the same way you did with $colname_GetCustomer.

Code: Select all

if (isset($_GET['cst_ID']) && isset($_GET['order_ID'])) { 
    $colname_GetCustomer = (get_magic_quotes_gpc()) ? $_GET['cst_ID'] : addslashes($_GET['cst_ID']); 
    $colname_GetOrder = (get_magic_quotes_gpc()) ? $_GET['order_ID'] : addslashes($_GET['order_ID']); 
}
Try this and post back with any errors or warnings if you get them.

Posted: Mon Jul 16, 2007 12:24 pm
by boo
dxm wrote:

Code: Select all

if (isset($_GET['cst_ID']) && isset($_GET['order_ID'])) { 
    $colname_GetCustomer = (get_magic_quotes_gpc()) ? $_GET['cst_ID'] : addslashes($_GET['cst_ID']); 
    $colname_GetOrder = (get_magic_quotes_gpc()) ? $_GET['order_ID'] : addslashes($_GET['order_ID']); 
}
Along with the code above you will need to do this to get in into your SQL statement

Code: Select all

$query_GetCustomer = sprintf("SELECT * FROM tbl_customers, tbl_orders 
WHERE order_ID = '%s' 
AND cst_ID = '%s'", $colname_GetOrder , $colname_GetCustomer);

Posted: Mon Jul 16, 2007 12:38 pm
by RobertGonzalez
Keep in mind that the conditional is checking && which means if one of the other is not set then the entire condition will evaluate to false and will not fire. Is that what you want?

Posted: Mon Jul 16, 2007 3:07 pm
by Addos
Thank you very much. Works a treat.

:lol: