stublackett Posted February 14, 2008 Share Posted February 14, 2008 Hi, I have a register form, Which checks User Levels and they can be set to Entrepeneur and Dragon I currently have PHP set to insert the $_POST value of 'level' and I've made another field in my database called userlevel What I'd like PHP to do is take the value of level and set it to TRUE or FALSE values depending on what was selected Entrepeneur or Dragon How do I go about this and then setting that variable as $userlevel ? Script is as follows : <?php #Script register.php By Stuart Blackett - d4066435@tees.ac.uk $username = $_POST['username']; $fullname = $_POST['fullname']; $email = $_POST['email']; $password = $_POST['password1']; $level = $_POST['level']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $city = $_POST['city']; $postcode = $_POST['postcode']; if (isset($_REQUEST['Submit'])) // Check $_POST['username'] and strip any slashes if (!empty($_POST['username'])) { $username = stripslashes($_POST['username']); }else{ $username = NULL; echo '<p><font color="red">You did not enter your desired username</font></p>'; } //Check Full Name if (!empty($_POST['fullname'])) { $fullname = ($_POST['fullname']); }else{ $fullname = NULL; echo '<p><font color="red">You did not enter your fullname</font></p>'; } //Check E-Mail Address if (!empty($_POST['email'])) { $email = ($_POST['email']); }else{ $email = NULL; echo '<p><font color="red">You did not enter your E-Mail Address</font></p>'; } //Check Password if (!empty($_POST['password1'])) { $password1 = ($_POST['password1']); }else{ $password1 = NULL; echo '<p><font color="red">You did not enter your First Password</font></p>'; } //Check User Level if $_POST['level']; == ['dragon']; $level = TRUE; }else{ $level = FALSE; } //Check E-Mail Address if (!empty($_POST['password2'])) { $password2 = ($_POST['password2']); }else{ $password2 = NULL; echo '<p><font color="red">You did not confirm your password</font></p>'; } //Check Address Line 1 if (!empty($_POST['address1'])) { $address1 = ($_POST['address1']); }else{ $address1 = NULL; echo '<p><font color="red">You need to specify the first line of your address</font></p>'; } //Check Address Line 2 if (!empty($_POST['address2'])) { $address2 = ($_POST['address2']); }else{ $address2 = NULL; echo '<p><font color="red">You need to specify the second line of your address</font></p>'; } //Check City if (!empty($_POST['city'])) { $city = ($_POST['city']); }else{ $city = NULL; echo '<p><font color="red">You need to specify the town or city you live in</font></p>'; } //Check Post Code if (!empty($_POST['postcode'])) { $postcode = ($_POST['postcode']); }else{ $postcode = NULL; echo '<p><font color="red">You need to specify your post-code</font></p>'; } // If everything is filled out print the message. if($username && $fullname && $email && $password && $address1 && $address2 && $city && $postcode) { { # If all is ok, Insert into DB $sql = "INSERT INTO $db_table(username,fullname,email,password,level,address1,address2,city,postcode,userlevel) values ('$username','$fullname','$email','$password','$level','$address1','$address2','$city','$postcode','$userlevel')"; // Incase needed($result = mysql_query($sql ,$db)); ($result = mysql_query($sql ,$db) or die(mysql_error())); echo "Thank you, <b>$username</b>. You have now registered<br /> With the details <b>:</b> <br /><b>Full Name</b> : $fullname<br /> <b>E-Mail</b> : $email <br /> and User Level : $level <br /> Thank You, You may Proceed to Login"; } ?> <?php ?> <?php } ?> I've highlighted where I'd like Userlevel to go, But its defining its value so I can check that when the user logs in Any suggestions appreciated, Thanks! Quote Link to comment Share on other sites More sharing options...
neverett Posted February 14, 2008 Share Posted February 14, 2008 Are you meaning like a variable that can be called up on any page? You might want to look into using sessions if that's the case. And do something like: if($level == "Dragon"){ $_SESSION['userlevel'] = true; }else{ $_SESSION['userlevel'] = false; } Or something along those lines. You might want to be a little more specific as to what variables you want set to what (as I'm slightly confused). Also this is incorrect: if $_POST['level']; == ['dragon']; It should be something like this: if($_POST['level'] == "dragon") Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 Are you meaning like a variable that can be called up on any page? You might want to look into using sessions if that's the case. And do something like: if($level == "Dragon"){ $_SESSION['userlevel'] = true; }else{ $_SESSION['userlevel'] = false; } Or something along those lines. You might want to be a little more specific as to what variables you want set to what (as I'm slightly confused). Also this is incorrect: if $_POST['level']; == ['dragon']; It should be something like this: if($_POST['level'] == "dragon") This is just for the register page to insert the value of 1 or 0 for User Level into the database, As each user of the site has different privelages depending on what option they select upon register if($_POST['level'] == "dragon") so thats saying if the selected option was dragon? That would then be defined as a TRUE or FALSE value so if($_POST['level'] == "dragon") $userlevel = true; }else{ $userlevel = false; Would that be the way to do it? Thanks Quote Link to comment Share on other sites More sharing options...
GameYin Posted February 14, 2008 Share Posted February 14, 2008 By default, 0 is guests, 1 is members, and 9 is admins. The range is 0-9. If you want to do so, just put the access level at 3 and let your website define what privileges will be appointed. Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 By default, 0 is guests, 1 is members, and 9 is admins. The range is 0-9. If you want to do so, just put the access level at 3 and let your website define what privileges will be appointed. Its just for a small project at University, I dont neccesarily need to go into the complexity of that, Just basically want to set user levels as 1's and 0's Quote Link to comment Share on other sites More sharing options...
neverett Posted February 14, 2008 Share Posted February 14, 2008 What I would do is this: if($_POST['level'] == "dragon"){ $userlevel = 1; // set userlevel = 1 if they selected Dragon }else{ $userlevel = 0; // set userlevel = 0 if they selected Entrepeneur } in place of this: if $_POST['level']; == ['dragon']; $level = TRUE; }else{ $level = FALSE; } I think that's the answer you're looking for. Quote Link to comment Share on other sites More sharing options...
stublackett Posted February 14, 2008 Author Share Posted February 14, 2008 Thats the one! Thanks for that Its probably better setting values of 1 and 0 rather than TRUE or FALSE Thanks Quote Link to comment Share on other sites More sharing options...
neverett Posted February 14, 2008 Share Posted February 14, 2008 No problem! Don't forget to mark this topic solved! Quote Link to comment Share on other sites More sharing options...
GameYin Posted February 14, 2008 Share Posted February 14, 2008 By default, 0 is guests, 1 is members, and 9 is admins. The range is 0-9. If you want to do so, just put the access level at 3 and let your website define what privileges will be appointed. Its just for a small project at University, I dont neccesarily need to go into the complexity of that, Just basically want to set user levels as 1's and 0's If you set it to zero. Your users will be mad because of no privileges. And If you have stuff on your site you need privileges on, then your guests will be very happy. No problem! Don't forget to mark this topic solved! There is no longer topic solved. It got taken off. 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.