OutOfInk Posted March 11, 2014 Share Posted March 11, 2014 (edited) 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 March 11, 2014 by OutOfInk Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 11, 2014 Share Posted March 11, 2014 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')){ Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 11, 2014 Share Posted March 11, 2014 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. Quote Link to comment Share on other sites More sharing options...
OutOfInk Posted March 11, 2014 Author Share Posted March 11, 2014 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? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 11, 2014 Share Posted March 11, 2014 (edited) You don't show enough in the hacked code to really show a good example, but give me a while to put something together. Edited March 11, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 11, 2014 Share Posted March 11, 2014 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> Quote Link to comment Share on other sites More sharing options...
OutOfInk Posted March 11, 2014 Author Share Posted March 11, 2014 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' Quote Link to comment Share on other sites More sharing options...
OutOfInk Posted March 11, 2014 Author Share Posted March 11, 2014 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 12, 2014 Share Posted March 12, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.