[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

PHP syntax in Dreamweaver

Posted on 2006-05-23
13
Medium Priority
?
185 Views
Last Modified: 2010-04-25
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'];
0
Comment
Question by:dereksheahan
  • 8
  • 5
13 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16747176
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;

0
 

Author Comment

by:dereksheahan
ID: 16747196
What is the better way of doing it?? :)
0
 

Author Comment

by:dereksheahan
ID: 16747548
sorry missed your code after your points!
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 

Author Comment

by:dereksheahan
ID: 16747574
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'];
}
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16747672
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.  
0
 

Author Comment

by:dereksheahan
ID: 16750694
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);
?>
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 1600 total points
ID: 16752529
One more error:

if ($_GET['cable_y_n'] == "No" OR !isset($_GET['cable_y_n']))

Post the form page again if the above doesn't fix it.
0
 

Author Comment

by:dereksheahan
ID: 16753350
Thanks Jason, spot on!
0
 

Author Comment

by:dereksheahan
ID: 16753364
All that's left to do now is submit this information to paypal I think and I'm done!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16753379
Damn.  I'm making a living here off of your points :)  You can't finish now...I'm not #1 all-time yet.
0
 

Author Comment

by:dereksheahan
ID: 16753435
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
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16753447
Cheers Derek...post a link to the finished product if possible...I'd love to look at it.
0
 

Author Comment

by:dereksheahan
ID: 16753481
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 :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question