Link to home
Start Free TrialLog in
Avatar of dereksheahan
dereksheahan

asked on

PHP syntax in Dreamweaver

Hi all,
I have a total price field that I'm trying to populate from two other variables. I want to display it so that if the url variable passed "cable_y_n is No then the cable price will be set to null. Otherwise the $checkout variable will include it. I need to change the syntax of the first part to make it work correctly.
Thanks,
D


if (isset($_GET['cable_y_n'])) = "No" {
  $row_RsCables['cab_cable_price'] = "";
}
$checkout = $log_price + $row_RsCables['cab_cable_price'];
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Derek,

Two things:

1. Shouldn't use null here.  Use zero.
2. You're trying to reassign a variable in an array and that's not the best way.

if (isset($_GET['cable_y_n'])) = "No" {
  $price = 0;
} else {
  $price = $row_RsCables['cab_cable_price'];
}

$checkout = $log_price + $price;

Avatar of dereksheahan
dereksheahan

ASKER

What is the better way of doing it?? :)
sorry missed your code after your points!
Hi Jason, tried your above suggestion but when I add this the page comes up blank in the browser?? Not sure what I'm doing wrong with it.

If (isset($_GET['cable_y_n'])) = "No" {
  $checkout = $log_price;
} else {
  $checkout = $log_price + $row_RsCables['cab_cable_price'];
}

I've also tried this but no joy :(

<?php if ($_GET['cable_y_n'] == "No") {
  $checkout = $log_price;
} else {
  $checkout = $log_price + $row_RsCables['cab_cable_price'];
}
Some other things I missed on the first one were parentheses and mis-use of isset():

if ($_GET['cable_y_n'] = "No") {
  $price = 0;
} else {
  $price = $row_RsCables['cab_cable_price'];
}
$checkout = $log_price + $price;

isset() is looking to see if the variable exists.  Can't compare it to "No" in the same equation.  If you are looking for "No" or is not set:

if ($_GET['cable_y_n'] = "No" OR !isset($_GET['cable_y_n'])) {
  $price = 0;
} else {
  $price = $row_RsCables['cab_cable_price'];
}
$checkout = $log_price + $price;

The only other thing you need to make sure of is that $row_RsCables['cab_cable_price'] is a numeric value.  
Hi Jason, when I insert your above code for some reason the whole cable section on the recieving seems to become hidden (you might remember me asking you to review my php syntax on a previous question to show/hide this region!). When I leave out the above code though, this area displays fine. I've tried putting the above statement on different parts of the page but that doesn't seem to fix it. The cable name and cable description remain hidden on the page and even when a cable is selected on the previous page, its value is not added to the $checkout variable? There's the code for the page as it stands anyways.
Thanks so much for your help,
D

<?php require_once('../Connections/GSM_mobile.php'); ?>
<?php
$colname_rsModel = "-1";
if (isset($_GET['Model'])) {
  $colname_rsModel = (get_magic_quotes_gpc()) ? $_GET['Model'] : addslashes($_GET['Model']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsModel = sprintf("SELECT type_table.type_type_id, type_table.type_type_name, model_table.mod_type_id, model_table.mod_model_id, model_table.mod_model_name FROM type_table, model_table WHERE model_table.mod_type_id =type_table.type_type_id  AND model_table.mod_model_id = %s", $colname_rsModel);
$rsModel = mysql_query($query_rsModel, $GSM_mobile) or die(mysql_error());
$row_rsModel = mysql_fetch_assoc($rsModel);
$totalRows_rsModel = mysql_num_rows($rsModel);

$colname_rsLogs = "-1";
if (isset($_GET['Model'])) {
  $colname_rsLogs = (get_magic_quotes_gpc()) ? $_GET['Model'] : addslashes($_GET['Model']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsLogs = sprintf("SELECT log_table.log_model_id, log_table.log_1, log_table.log_2, log_table.log_5 FROM log_table WHERE log_table.log_model_id = %s ", $colname_rsLogs);
$rsLogs = mysql_query($query_rsLogs, $GSM_mobile) or die(mysql_error());
$row_rsLogs = mysql_fetch_assoc($rsLogs);
$totalRows_rsLogs = mysql_num_rows($rsLogs);

$colname_RsCables = "-1";
if (isset($_GET['Cable'])) {
  $colname_RsCables = (get_magic_quotes_gpc()) ? $_GET['Cable'] : addslashes($_GET['Cable']);
}
mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_RsCables = sprintf("SELECT cable_table.cab_cable_id, cable_table.cab_cable_name, cable_table.cab_cable_price, cable_table.cab_desc FROM cable_table WHERE cable_table.cab_cable_id = %s", $colname_RsCables);
$RsCables = mysql_query($query_RsCables, $GSM_mobile) or die(mysql_error());
$row_RsCables = mysql_fetch_assoc($RsCables);
$totalRows_RsCables = mysql_num_rows($RsCables);



switch ($_GET['log_select']) {
    case "log_1":
        $log_price = $row_rsLogs['log_1'];
            $log_label = "1";
        break;
    case "log_2":
        $log_price = $row_rsLogs['log_2'];
            $log_label = "2";
        break;
    case "log_5":
        $log_price = $row_rsLogs['log_5'];
            $log_label = "5";
        break;
    default:
        die("You stupid git, you didn't select a log on the previous page.  What do you expect me to do here, read your mind?");
}
if ($_GET['cable_y_n'] = "No" OR !isset($_GET['cable_y_n'])) {
  $price = 0;
} else {
  $price = $row_RsCables['cab_cable_price'];
}
$checkout = $log_price + $price;


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>Checkout:</p>
  <p>
    <label>Phone Brand:
    <input name="phone_brand" type="text" id="phone_brand" value="<?php echo $row_rsModel['type_type_name']; ?>" />
    </label>
  </p>
  <p>
    <label>Phone Model:
    <input name="phone_model" type="text" id="phone_model" value="<?php echo $row_rsModel['mod_model_name']; ?>" />
    </label>
  </p>
  <p>
    <label><?php echo $log_label; ?> Log(s):
    <input name="log_price_text" type="text" id="log_price_text" value="<?php echo $log_price; ?>" />
    </label>
  </p>
  <?php if ($_GET['cable_y_n'] == "Yes") { ?>
 
    <p>
      <label>Cable Name:
      <input name="textfield4" type="text" value="<?php echo $row_RsCables['cab_cable_name']; ?>" size="40" />
      </label>
  </p>
    <p>
      <label>Cable Description:
      <textarea name="textarea" cols="35" rows="4"><?php echo $row_RsCables['cab_desc']; ?></textarea>
      </label>
  </p>
    <?php } ?><p>
    <label>Total:
    <input name="textfield5" type="text" value="<?php echo $checkout; ?>" />
    </label>
  </p>
  <p>
    <label>Proceed To Paypal Checkout
    <input type="submit" name="Submit" value="Submit" />
    </label>
  </p>
  <p>&nbsp;</p>
</form>
</body>
</html>
<?php
mysql_free_result($rsModel);

mysql_free_result($rsLogs);

mysql_free_result($RsCables);
?>
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Jason, spot on!
All that's left to do now is submit this information to paypal I think and I'm done!
Damn.  I'm making a living here off of your points :)  You can't finish now...I'm not #1 all-time yet.
lol, just closed at a lot of questions there and most of them will were answered by you so not to worry! Took on another smaller project anyways so there'll be more on the way :)
cheers jason
Cheers Derek...post a link to the finished product if possible...I'd love to look at it.
I will of course, just have to do a small few things and I'll have it up on the server. I'm in the process of writing a question about Paypal integration if you have time to have a look at.
Don't worry, you'll be the first to see the finished product, I promise :)