Jump to content

[SOLVED] Checkboxes


blink359

Recommended Posts

I have 2 checkboxes in my form i want it so only one can be ticked at a time i need it when tbc box is checked its worth the value 8 if wotlk is checked its worth the value 24 and if none are check its worth the value 0 can anyone help me on this?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:9px;
top:336px;
width:1144px;
height:40px;
z-index:1;
}
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
#apDiv2 {
position:absolute;
left:13px;
top:417px;
width:934px;
height:1657px;
z-index:1;
}
#apDiv3 {
position:absolute;
left:32px;
top:32px;
width:593px;
height:101px;
z-index:2;
}
.style1 {
font-size: xx-large
}
-->
</style>
</head>

<body>
<div id="apDiv2">
<?php 
$dbhost = "DBHOST"; 
$dbuser = "DBUSER"; 
$dbpass = "DBPASS"; 
$dbname = "DBNAME"; 


mysql_connect($dbhost, $dbuser, $dbpass); 
mysql_select_db($dbname); 
  
$user = $_POST['user']; 
$pass = $_POST['pass']; 
$pass2 = $_POST['pass2']; 
  
$success = true; 
$problemMessage = ""; 
if (isset($_POST['Submit'])) 
{ 
        if(!$user || !$pass || !$pass2) 
        { 
            $problemMessage .= "Please complete all required data <br />"; 
            $success = false; 
        } 
        if(strlen($user) < 5) 
        { 
            $problemMessage .= "User must be more that 5 characters <br />"; 
            $success = false; 
        } 
        if(strlen($user) > 20) 
        { 
            $problemMessage .= "Your username cannot be longer than 20 characters <br />"; 
            $success = false; 
        } 
        if($pass != $pass2) 
        { 
            $problemMessage .= "Your passwords do not match <br />"; 
            $success = false; 
        } 
        if(strlen($pass2) < 5) 
        { 
            $problemMessage .= "Your password must be more than 5 characters<br />"; 
            $success = false; 
        } 
        if(strlen($pass2) > 20) 
        { 
            $problemMessage .= "Your password cannot be longer than 20 characters <br />"; 
            $success = false; 
        }  
         
        if ($success) 
        { 
            echo "Valid New Account Entry<br />"; 
            $result = mysql_query("INSERT INTO `accounts` VALUES ('6', '$user', '$pass2', '', '', '0', '9', '', '', '24', 'enUS', '0', '0', null)")  
             or die("Error: (" . mysql_errno() . ") " . mysql_error()); 
        } 
} 

  
?> 

<?php 
if ($success == false) { 
    echo $problemMessage; 
} 
?> 
<center><form method="post" action=""> 
    Account Creation Page<br> 
    Username: <input name="user" type="text"/><br>  
    Password: <input name="pass" type="text"/><br>  
    Repeat Password: <input name="pass2" tpye="text"/><br>  
    The burning Crusade: <inputname="tbc" type="checkbox"/><br>
    Wrath of the lich king: <inputname="wotlk" type="checkbox"/><br>
    <input name="Submit" type="submit" value="submit" /> 
    <imput name="reset" type="reset" value="reset" /> 
</form></center>  </h1></div>
<div id="apDiv3">
  <h1 class="style1">Server Name Goes here</h1>
</div>
<p><img src="Images/Image2.jpg" width="1143" height="321" /></p>
<p><a href="index.html"><img src="Images/Home.jpg" width="150" height="50" /></a><a href="phpbb3/index.php"><img src="Images/Forums.jpg" width="150" height="50" /></a><a href="Register.php"><img src="Images/Create.jpg" width="250" height="50" /></a><a href="vote.php"><img src="Images/Vote.jpg" width="150" height="50" /></a><a href="donate.html"><img src="Images/Donate.jpg" width="150" height="50" /></a></p>
<p> </p>
</body>


</html>

Link to comment
Share on other sites

Could i do something like

$_POST['user'];

$result = mysql_query("INSERT INTO `accounts` VALUES ('6', '$user', '$pass2', '', '', '0', '9', '', '', '$_POST['none'] OR $_POST['tbc'] OR $_POST['wotlk']', 'enUS', '0', '0', null)") 

 

and before the ifs do

$_POST['none'] = "0";
$_POST['tbc'] = "8";
$_POST['wotlk'] = "24";

Link to comment
Share on other sites

Could i do something like

$_POST['user'];

$result = mysql_query("INSERT INTO `accounts` VALUES ('6', '$user', '$pass2', '', '', '0', '9', '', '', '$_POST['none'] OR $_POST['tbc'] OR $_POST['wotlk']', 'enUS', '0', '0', null)") 

 

and before the ifs do

$_POST['none'] = "0";
$_POST['tbc'] = "8";
$_POST['wotlk'] = "24";

 

why would you do that? I dont understand.. You are trying to set one column to have the value 0, 8, or 24 right. Just use the HTML and a radio button to set one Post variable to either 0, 8, or 24 and put that value into the table. No if statements are needed at all

Link to comment
Share on other sites

Im trying to make the values get put into the mysql statement here

$result = mysql_query("INSERT INTO `accounts` VALUES ('6', '$user', '$pass2', '', '', '0', '9', '', '', 'VALUES GO HERE', 'enUS', '0', '0', null)")

 

so i could use

   

Pre TBC<input type="radio" name="pretbc" value="0"> 0<br>
    TBC Enabled<input type="radio" name="tbc" value="8"> 8<br>
    Wotlk Enabled<input type="radio" name="wotlk" value="24"> 24<br>

and before the ifs with

$user = $_POST['user']; 
$pass = $_POST['pass']; 
$pass2 = $_POST['pass2']
do
$none = $_POST['none''];
$tbc = $_POST['tbc'];
$wotlk = $_POST['wotlk'];;

so

$result = mysql_query("INSERT INTO `accounts` VALUES (;

'6', '$user', '$pass2', '', '', '0', '9', '', '', '$none OR $tbc OR $wotlk', 'enUS', '0', '0', null)")
;

Link to comment
Share on other sites

there is only 1 flags column. All you need to create a user is something like this:

$flag = ; //put the flag here. either 0,8, or 24.  I use 51 in stead of 24, but to each their own
$sql = "INSERT INTO accounts(login,password,encrypted_password,gm,email,flags,lastip) VALUES('$login','$password','$sha1pass',0,'$email',$flag,'$ip');";

Link to comment
Share on other sites

can i do it so they tick the boxes for there account type

 

if so whats the php so that i give the radio boxes or dropdown values so

pre tbc is worth 0 if its put into mysql query

tbc is worth 8 if its put into mysql query

wotlk is worth 24 if  ts put into mysql query

 

and then i put in the mysql query where it goes

'$none OR $tbc OR $wotlk",

Link to comment
Share on other sites

yes but ya will recieve notices of undefined variables

 

and yer query may not be what u expect.

As said, Checkboxes/radio buttons only return a key/value pair if its selected/checked

so the other values wont be sent for processing

and yer sql statement with

'$none OR $tbc OR $wotlk'

 

becomes

OR OR 24

or

OR 8 OR

or

0 OR OR

 

Link to comment
Share on other sites

Oh i see i think:

 

HTML =

Pre TBC<input type="radio" name="flag" value="0" /> 
TBC Enabled<input type="radio" name="flag" value="8" /> 
WOTLK Enabled<input type="radio" name="flag" value="24" />

 

PHP =

$flag = $_POST['flag'];

Then for mysql Query

$result = mysql_query("INSERT INTO `accounts` VALUES ('', '$user', '$pass2', '', '', '0', '9', '', '', '$flag', 'enUS', '0', '0', null)")

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.