magi Posted May 13, 2007 Share Posted May 13, 2007 Hi everyone, sorry to bother again but im having trouble with a check im trying to do Its in the admin panel for a game i own, and i cant figure it out. I can add the "summon" no problem, but my issue is that the summon is for a specific race only. I need to check if they typed in the race or not before it goes to the DB . So heres an example Summon Race: frghkdjghde <--- I dont want that, i want it to output an error that its not right Summon Race: Race <---- If that was a race that the summon was for, it would be god and not a bunch of letters. If someone would help it would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/ Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php $races = array("God", "Zeus"); // Edit this array to contain the names of the valid gods if(in_array($race, $races)) { // Database query } else { die("The race $race is not a valid race."); } ?> Use that code where $race is the user's race they have typed in. Edit the $races array to have values of each valid race. Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252040 Share on other sites More sharing options...
AndyB Posted May 13, 2007 Share Posted May 13, 2007 Just to add to chigley's post, you might want to include trim(), and possibly strtolower() or strtoupper(), on the user input so that whitespace is removed and zeus is as good as Zeus. Or solve the whole problem by having the user select from a dropdown of acceptable gods. That way, it's impossible for the user to get it wrong. Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252043 Share on other sites More sharing options...
magi Posted May 13, 2007 Author Share Posted May 13, 2007 After i Click Add Summon, it goes through the check, and all my other checks are like this if (($_POST[sumtype]>=1&&$_POST[sumtype]<=3)&&preg_match("|^[0-9]*$|",$_POST[sumtype])) $check23=1; That works fine , however i want it to do something liek this if ($_POST[sumrace]=Race1, Race2, Race3)$check24=1; However i have tried that and it will not work. my $check 24=1 is if ($check24!=1) $message[]="Please key in a valid value for Summon Race."; Thanks again How woulkd i make them select from the dropdown box and insert it into the database? Because in the database it has to be the word, not a number pertaining to the race ... ny help once again would be great. Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252051 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php // Instead of: if ($_POST[sumrace]=Race1, Race2, Race3)$check24=1; // Use: $races = array("Race1", "Race2", "Race3"); if(in_array($races, $_POST[sumrace])) { $check24 = 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252055 Share on other sites More sharing options...
magi Posted May 13, 2007 Author Share Posted May 13, 2007 Well, thank you, but now i get this warning Warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\WebRoot\staffsummon.php on line 64 This is my summon race form code echo'<tr><td class="admincellleft1">Summon Race:<span class="littletextred1"><br>Lexima , Hexion , or Celestial</span>'; echo'<td class="admincellleft1"><input class="inputp1" type="text" name="sumrace" size="10" maxlength="10" value="'.$_POST[sumrace].'"></td></tr>'; Also, if i put in a bad race name, it says my error message, however, if its the right race name, i still get an error message. :S:S:S Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252059 Share on other sites More sharing options...
AndyB Posted May 13, 2007 Share Posted May 13, 2007 How woulkd i make them select from the dropdown box and insert it into the database? Because in the database it has to be the word, not a number pertaining to the race ... Straightforward html ... <select name="god"> <option value="">Choose God</option> <option value="Zeus">Zeus</option> <option value="Thor">Thor</option> ... more options ... </select> And then in the form processing script, the selected god is $_POST['god']. Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252098 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 You still need to run a check though if this is a script that users will access because there's always Javascript injections that mean somebody else can change your value to an invalid God name! Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252100 Share on other sites More sharing options...
magi Posted May 13, 2007 Author Share Posted May 13, 2007 Thanks guys, its fixed now and it works great really appreciated Quote Link to comment https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/#findComment-252275 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.