Jump to content

String Variable Changing value and hidden value not working


OutOfInk

Recommended Posts

For some reason, my variable is changing its value to 'Draw' everytime. Draw is onyl one of 18 possible outcomes

 

echo "[[[[[[[ $arrayTeam / $arrayBet / $arrayRound / $drawwww ]]]]]]]]]]]]]";  <-- At this point all variables are correct and than the below script isnt keeping thoses values.
 
if (($checkBids > 0) && ($arrayTeam = 'Draw')){
mysql_query("UPDATE
mysql_query("UPDATE
echo "<font color='red'>You have updated your bid that <b>$fdraw[0]</b> and <b>$fdraw[1]</b> will draw round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC as your bet!</font>";
}elseif (($checkBids > 0) && ($arrayTeam != 'Draw')){
mysql_query("UPDATE
mysql_query("UPDATE 
echo "<font color='red'>You have updated your bid for <b>$arrayTeam</b> to win on round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC!</font>";
}elseif (($checkBids < 1) && ($arrayTeam = 'Draw')){
mysql_query("UPDATE
mysql_query("INSERT INTO
echo "<table cellpadding='2' cellspacing='0' border='0' class='innnertable' width='620'>";
echo "<tr class='innertable'><td align='center'>";
echo "<font color='green'>You placed a bet that <b>$fdraw[0]</b> and <b>$fdraw[1]</b> will draw round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC as your bet!</font>";
echo "</td></tr></table>";
}elseif (($checkBids < 1) && ($arrayTeam != 'Draw')){
mysql_query("UPDATE
mysql_query("INSERT INTO
echo "<table cellpadding='2' cellspacing='0' border='0' class='innnertable' width='620'>";
echo "<tr class='innertable'><td align='center'>";
echo "<font color='green'>You placed a bet on <b>$arrayTeam</b> to win for round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC as your bet!</font>";
echo "</td></tr></table>";
 
 
Also im using a while statement to pull data from the mysql db, all values are fine except my hidden value keeps defaulting to the last value.
 
$leader = mysql_query("SELECTxxxx
while ($redeal = mysql_fetch_row($leader)){
echo "<input type='hidden' name='round' value='$redeal[6]' />";
echo "<tr class='innertable'>";
echo "<td><input type='radio' name='beton' value='$redeal[0]' /></td>";
echo "<td align=left>$redeal[0]($<b>".number_format($redeal[3], 2)."</b>)</td>";
echo "<td>V</td>";
echo "<td><input type='radio' name='beton' value='$redeal[1]' /></td><td align=left>$redeal[1] ($<b>".number_format($redeal[4], 2)."</b>)</td>";
echo "<td align=left><input type='radio' name='beton' value='Draw' /> $51.00</td>";
echo "<td align=left>$redeal[2]</td>";
echo "<td align=left>$redeal[7]<br />$redeal[8]</td></tr><input type='hidden' name='pwnow' value='$redeal[5]' />"; < THIS HIDDEN value displays the correct value but as soon as i post the its not correct. I checked the Html source to ensure the values are correct but in the php script its not recognizing the value and choosing the last value='9' instead of whats selected 
}
Edited by OutOfInk
Link to comment
Share on other sites

Your problem is on the very first line

 

if (($checkBids > 0) && ($arrayTeam = 'Draw')){

 

 . . . or more precisely

 

$arrayTeam = 'Draw'

 

That is not comparing the variable $arrayTeam tot he string 'Draw', it is assigning the string 'Draw' to the variable $arrayTeam

 

To compare you use two equal signs

 

if (($checkBids > 0) && ($arrayTeam == 'Draw')){
Link to comment
Share on other sites

 

Also im using a while statement to pull data from the mysql db, all values are fine except my hidden value keeps defaulting to the last value.

 

Because you are giving the hidden fields the same name. So, if you replicate the hidden fields and they are all submitted with the form, then the value of the last one is what will get passed.

 

But, to tell you the truth, the format of your code is atrocious. You need to take a more structured approach to your code. All those ifelse() statements should be simplified and you should only include logic in those conditions - then create the output later.

Link to comment
Share on other sites

Thanks Psycho, worked perfect, == makes perfect sense.  Could you give me a very short example of a more simplified approach instead of using multiple ifelse to check user data isn't malicious  and correct data is entered that you would take?

Link to comment
Share on other sites

OK, looking at your original code it is impossible to tell if you are running any of the same queries. But, if you are duplicating any of those queries you should not write them twice in the code - instead structure your logic so you only need to run them once. Below is some "mock" code based upon what you posted with some assumptions that the first queries were duplicated. I also made the assumption that $checkBids is a Boolean value (true/false).

 

Some other things: Don't use the FONT tag it has been deprecated for over a decade! And, don't put presentation logic in the code.

 

Again, this was based on a lot of assumptions

 

<?php

if (!$checkBids)
{
    //Run processes for when $checkBids is false
    mysql_query("UPDATE");
    $responseClass = 'redclass';

    if ($arrayTeam == 'Draw')
    {
        mysql_query("UPDATE");
        $response = "You have updated your bid that <b>$fdraw[0]</b> and <b>$fdraw[1]</b> will draw round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC as your bet!";
    }
    else
    {
        mysql_query("UPDATE");
        $response = "You have updated your bid for <b>$arrayTeam</b> to win on round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC!";
    }

}
else
{
    //Run processes for when $checkBids is true
    mysql_query("UPDATE");
    $responseClass = 'greenclass';

    if($arrayTeam == 'Draw')
    {
        mysql_query("INSERT INTO");
        $response = "You placed a bet that <b>$fdraw[0]</b> and <b>$fdraw[1]</b> will draw round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC as your bet!";
    }
    else
    {
        mysql_query("INSERT INTO");
        $response = "You placed a bet on <b>$arrayTeam</b> to win for round <b>$arrayRound</b>, placing <b>$arrayBet</b> PPC as your bet!";
    }
}

?>
<table cellpadding='2' cellspacing='0' border='0' class='innnertable' width='620'>
    <tr class='innertable'>
        <td align='center' class="<?php echo $responseClass; ?>"><?php echo $response; ?></td>
    </tr>
</table>
Link to comment
Share on other sites

Also could you clear up how I would resolve the hidden input issue

 

<input type='hidden' name='pwnow' value='$redeal[5]' />

 

Im gathering my other hidden input has the same issue but i haven't came across it yet since they all share the same value of '1'

Link to comment
Share on other sites

OKay that example makes sense, haha really font is no longer a go! It has been about 5 years since ive really done any coding, So I am playing catch up atm

 

Thanks 

 

Hmm, the font tag has officially been deprecated for a full 15 years - since the release of HTML 4.01 in 1999. So, even if you were coding 5 years ago it had been deprecated for at least 10 years before that! But, it's all good, the internet is strewn with tutorials and examples that still use it. Which explains why it we still see it so much here.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.