Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/51189-solved-specific-name-check/
Share on other sites

<?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.

 

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.

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.

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

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'].

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.