blink359 Posted April 24, 2009 Share Posted April 24, 2009 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> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2009 Share Posted April 24, 2009 use radio buttons instead. Quote Link to comment Share on other sites More sharing options...
laffin Posted April 24, 2009 Share Posted April 24, 2009 Why not just use a radio button? checkboxes and radio buttons have the same name, but only the ones checked get sent to get/post. Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 24, 2009 Author Share Posted April 24, 2009 Ok thanks for that but any chance for the code to make tbc work 8 wotlk worth 24 and none checked worth 0? Quote Link to comment Share on other sites More sharing options...
laffin Posted April 24, 2009 Share Posted April 24, 2009 Thats html not php <input type="radio" name="wotlk" value="0"> 0<br> <input type="radio" name="wotlk" value="8"> 8<br> <input type="radio" name="wotlk" value="24"> 24<br> whatever is ticked gets sent to the script. Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 24, 2009 Author Share Posted April 24, 2009 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"; Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 24, 2009 Share Posted April 24, 2009 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 Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 24, 2009 Author Share Posted April 24, 2009 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)") ; Quote Link to comment Share on other sites More sharing options...
laffin Posted April 24, 2009 Share Posted April 24, 2009 Q: Why have an option of 3 choices, if in the processing yer going to use all three? It kinda defeats the purpose. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2009 Share Posted April 24, 2009 You're using ArcEmu. Just use the radio buttons. i know how ArcEmu works (seeing how I help when I can on their site). Trust me, radio/dropdown is the way you will want to go. Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 24, 2009 Author Share Posted April 24, 2009 So jons that would work right? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 24, 2009 Share Posted April 24, 2009 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');"; Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 24, 2009 Author Share Posted April 24, 2009 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", Quote Link to comment Share on other sites More sharing options...
laffin Posted April 24, 2009 Share Posted April 24, 2009 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 Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 24, 2009 Author Share Posted April 24, 2009 So whats the php code to make the radio boxes put the values into the mysql query? Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 25, 2009 Author Share Posted April 25, 2009 Still confused about what i need to do to get the 0 or 8 or 24 included in the mysql query depending on what radio button they used Quote Link to comment Share on other sites More sharing options...
blink359 Posted April 25, 2009 Author Share Posted April 25, 2009 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)") 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.