Jump to content

Recommended Posts

Is it possible for php the check for individual letters in a sql record. For example is the word 'superman' was stored in sql record and my page told the user to input the first, fourth and last letter of the word into a text box would php be able to check the record to see if the letter exists the word and that they are in the correct order?

Link to comment
https://forums.phpfreaks.com/topic/213501-possible-with-php-and-mysql/
Share on other sites

You would need to pull the word out of the database then test it for the letters. If you had asked for letters 1,3&4 you would do somehting like this

 

 

if ($secret_word[0] == 's' && $secret_word[2] == 'p' && $secret_word[3] == 'e') {
<Do something>
}

 

Since this word in stored in a database, you would generally want to do this in a query and check if the query matched any row(s) -

 

$first, $fourth, and $last php variables hold the entered characters. The underscore _ wildcard character ignores the 2nd, 3rd, 5th, 6th, and 7th positions -

 

$query = "SELECT COUNT(*) FROM your_table WHERE your_column LIKE '$first__$fourth___$last' AND another_condition_that_identifies_the_specific_word_you_want_to_check"

i want to write a code, which will ask for different letters every time and once the user has submitted the form with the text box in it will then check to see if the letters are correct and in the right order from what the first page had indicated to the user.

 

 

I have just read a short tutorial on wildcard in php, i cant access my ftp at the moe so i cant try the code.

 

Dont no if this will work, does this seem right?

$word = superman
$match = $word[1].$word[2].$word[5];
if ($pWord == $match) {
echo "ya mar";
}

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.