Jump to content

Checkboxes problem


SSFM

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/108177-checkboxes-problem/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/108177-checkboxes-problem/#findComment-554536
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/108177-checkboxes-problem/#findComment-554551
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.