SSFM Posted May 31, 2008 Share Posted May 31, 2008 Ok so, I've set up a form with both textboxes and checkboxes. <form action="gmmaker.php" method="POST"> <tr><td class="list" align="right">Login Name:</td><td class=list><input type="text" name="name" maxlength="30"></td></tr> <tr><td class="list" align="right">Charname:</td><td class=list><input type="text" name="charname" maxlength="30"></td></tr> <tr><td class="list" align="right">Admin Password:</td><td class=list><input type="adminpass" name="adminpass" maxlength="30"></td></tr> <td><td class="list" align="left"><input type="checkbox" name="accountgm"<?php if($accountgm == "on"){echo" CHECKED";}?>> Make Account GM</td></tr> <td><td class="list" align="left"><input type="checkbox" name="charactergm"<?php if($charactergm == "on"){echo" CHECKED";}?>> Make Character GM</td></tr> <td><td class="list" align="left"><input type="checkbox" name="maxstats"<?php if($maxstats == "on"){echo" CHECKED";}?>> Max stats (STR, DEX, LUK, HP, MP)</td></tr> <td><td class="list" align="left"><input type="checkbox" name="maxlevel"<?php if($maxlevel == "on"){echo" CHECKED";}?>> Max level (200) +1000 SP</td></tr> <td><td class="list" align="left"><input type="checkbox" name="hugemesos"<?php if($hugemesos == "on"){echo" CHECKED";}?>> 1,000,000,000 Mesos</td></tr> <tr><td class="listtitle" align="center" colspan="2"><input type="submit" name="submit" value="Do it!"><br><br><br><br><br><br><br><br><br></td></tr> </form> (the text fields work fine btw, I tested them beforehand) After submitting, it goes to another page where it checks the value by using this: $accountgm == $_POST['accountgm']; $charactergm == $_POST['charactergm']; ...etc then performs actions based on the results. However, it did the same thing regardless of whether the boxes were checked or not. So I used this... echo "$accountgm" And every time the result was the same. It displayed '1'. So how do I get it to recognize the value properly? Quote Link to comment https://forums.phpfreaks.com/topic/108177-checkboxes-problem/ Share on other sites More sharing options...
.josh Posted June 1, 2008 Share Posted June 1, 2008 I don't see any value ="blah" in your input fields. Also, == is a condition operator not an assignment operator. Quote Link to comment https://forums.phpfreaks.com/topic/108177-checkboxes-problem/#findComment-554520 Share on other sites More sharing options...
SSFM Posted June 1, 2008 Author Share Posted June 1, 2008 Ok, but I don't exactly know how to use value... <td><td class="list" align="left"><input type="checkbox" name="accountgm" value='true' ....etc But now what? Quote Link to comment https://forums.phpfreaks.com/topic/108177-checkboxes-problem/#findComment-554527 Share on other sites More sharing options...
art15 Posted June 1, 2008 Share Posted June 1, 2008 Hi, You can try checking the checkbox value. not assocaiate the name with the if condition. let the name be as it is but value="if( condition) checked) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/108177-checkboxes-problem/#findComment-554532 Share on other sites More sharing options...
SSFM Posted June 1, 2008 Author Share Posted June 1, 2008 Erm... Either I don't understand what you're saying or you don't understand what I'm saying. xD Here's part of the script on the page it goes to: if($adminpass == '') { echo 'Admin password was left blank! '; } else if($adminpass != "<INSERT_PASS>") { echo "The admin password was wrong! "; } if($accountgm = 1) { if(mysql_num_rows(mysql_query($sel2)) != 1 || $name = '') { echo "Account does not exit! $accountgm "; } } if($charactergm = 1 || $maxstats = 1 || $hugemesos = 1 || $maxlevel = 1) { if(mysql_num_rows(mysql_query($sel)) != 1 || $charname = '') { echo 'Character does not exist! '; } } else { if($adminpass == "<INSERT_PASS>") { mysql_query($fix); { if($accountgm = 1) { $d = 'UPDATE accounts SET gm="1" WHERE name="'.$name.'"'; mysql_query($d) OR die (mysql_error()); echo 'Account '+$name+' is now a GM! New characters will be GMs as well. '; } if($charactergm = 1) { $d = 'UPDATE characters SET gm="1" WHERE name="'.$charname.'"'; mysql_query($d) OR die (mysql_error()); echo 'Character '+$charname+' is now a GM! '; } The 'if($charactergm = 1)' and such is supposed to check if the checkbox is checked. But I have a feeling that's wrong. So I'm asking HOW do I make it set the value accordingly, and check for the value instead? Quote Link to comment https://forums.phpfreaks.com/topic/108177-checkboxes-problem/#findComment-554536 Share on other sites More sharing options...
.josh Posted June 1, 2008 Share Posted June 1, 2008 In your first script posting you had no value=".." in your input fields. The 2nd one you have value="true" What "value" exactly are you trying to find out? You said earlier it's returning "1" well "true" = "1". Look, it's really not that hard to have a checkbox and then have a script check to see if it has been checked: form: <form action = 'somepage.php' method = 'post'> <input type = 'checkbox' name = 'blah' value = 'someval'> check me <br /> <input type = 'submit' value = 'submit'> </form> somepage.php <?php if ($_POST['blah']) { echo "checkbox was checked! checkbox data: {$_POST['blah']}"; } else { echo "checkbox not checked!"; } ?> so...if that's not the issue, then I guess we're not understanding you. Quote Link to comment https://forums.phpfreaks.com/topic/108177-checkboxes-problem/#findComment-554551 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.