Jump to content


Photo

If statments not working


  • Please log in to reply
5 replies to this topic

#1 kasc

kasc
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 March 2006 - 08:57 AM

Ok, this script at the moment isn't working for the catching the errors. Here it is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Your Result</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$start = $_POST["start"];
$end = $_POST["end"];

echo "$start $end<br>";

$errors = 0;
if ($start = "unchoosen" || $end = "unchoosen" || $start >= $end) {
    echo "ERRORS:<br>";
    if ( $start = "unchoosen" ) {
        echo "<br> You did not choose your starting value for your item!";
        $errors = $errors + 1;
        }
    if ( $end = "unchoosen" ) {
        echo "<br> You did not choose your desired value for your item!";
        $errors = $errors + 1;
        }
    if ( $start >= $end ) {
        echo "<br> Your combination of upgrading values are impossible!";
        $errors = $errors + 1;
        } 
    echo "<br>Total Errors: $errors";
    }
?>
</body>
</html>
$start and $end are taken from a drop down box, and they return the right values, jsut the if statement not working, since no matter what the combination (Possible values $start = "unchoosen", 0-8; $end = "unchoosen", 1-9) It always ehcos all 3 errors. :(

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 March 2006 - 09:31 AM

if ($start [!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]=[!--colorc--][/span][!--/colorc--] "unchoosen"

To compare values use "==" and not "="

In the statement above you have set the value of $start to "unchoosen" instead of comparing it.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 kasc

kasc
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 March 2006 - 09:40 AM

[!--quoteo(post=356122:date=Mar 18 2006, 09:31 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Mar 18 2006, 09:31 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if ($start [!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]=[!--colorc--][/span][!--/colorc--] "unchoosen"

To compare values use "==" and not "="

In the statement above you have set the value of $start to "unchoosen" instead of comparing it.
[/quote]

^_^ Thanks for that.

#4 kasc

kasc
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 March 2006 - 11:26 AM

Another snag, this is returning Parse error: parse error, unexpected '$' in /home/kascgam/public_html/upgrading/upgrading.php on line 43

if ( $start !== "unchoosen" && $end !== "unchoosen" && $start < $end ) {
    $items = 1;
    
    /* LINE 43 start = 0 */
    
    if ($start == 0 $$ $end == 1) {
        $items = 2;
        }
    elseif ($start == 0 $$ $end == 2) {
        $items = 4;
        }
    elseif ( start == 0 $$ $end == 3) {
        $items = 10;
        }
    elseif ($start == 0 $$ $end == 4) {
        $items = 28;
        }
    elseif ($start == 0 $$ $end == 5) {
        $items = 82;
        }
    elseif ($start == 0 $$ $end == 6) {
        $items = 244;
        }
    elseif ($start == 0 $$ $end == 7) {
        $items = 730;
        }
    elseif ($start == 0 $$ $end == 8) {
        $items = 2188;
        }
    elseif ($start == 0 $$ $end == 9) {
        $items = 6562;
        }
    /* start = 1 */
    echo "You need $items +1 items";
    }
(Line 43 is the top comment)

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 March 2006 - 11:40 AM

if ($start == 0 [!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]$$[!--colorc--][/span][!--/colorc--] $end == 1) {
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 March 2006 - 12:36 PM

Rather than two $$ I think you will want either teo || (|| means OR) or two && (&& meaning AND).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users