Jump to content

help with making string from <OPTION> values


seany123

Recommended Posts

okay all i need is a way to make 4 <OPTION> values into a string which i can compare to a row in my db.

 

This is my form.

<select name='n1'> 
        <option value='0'>0</option> 
        <option value='1'>1</option> 
        <option value='2'>2</option> 
        <option value='3'>3</option> 
        <option value='4'>4</option> 
        <option value='5'>5</option> 
        <option value='6'>6</option> 
        <option value='7'>7</option> 
        <option value='8'>8</option> 
        <option value='9'>9</option> 
    </select> 
    <select name='n2'> 
        <option value='0'>0</option> 
        <option value='1'>1</option> 
        <option value='2'>2</option> 
        <option value='3'>3</option> 
        <option value='4'>4</option> 
        <option value='5'>5</option> 
        <option value='6'>6</option> 
        <option value='7'>7</option> 
        <option value='8'>8</option> 
        <option value='9'>9</option> 
    </select> 
    <select name='n3'> 
        <option value='0'>0</option> 
        <option value='1'>1</option> 
        <option value='2'>2</option> 
        <option value='3'>3</option> 
        <option value='4'>4</option> 
        <option value='5'>5</option> 
        <option value='6'>6</option> 
        <option value='7'>7</option> 
        <option value='8'>8</option> 
        <option value='9'>9</option> 
    </select> 
    <select name='n4'> 
        <option value='0'>0</option> 
        <option value='1'>1</option> 
        <option value='2'>2</option> 
        <option value='3'>3</option> 
        <option value='4'>4</option> 
        <option value='5'>5</option> 
        <option value='6'>6</option> 
        <option value='7'>7</option> 
        <option value='8'>8</option> 
        <option value='9'>9</option> 
    </select>

 

here is the php code which i tried but doesnt seem to work.

       $n1 = $_POST['n1'];
       $n2 = $_POST['n2'];
       $n3 = $_POST['n3'];
       $n4 = $_POST['n4'];
       
       $string = ("" . $n1 . "" . $n2 . "" . $n3 . "" . $n4 . "");

 

echoing $string does give to correct numbers.. but when i try and compare it to my database it doesnt match.

 

 

all help would be great.

Link to comment
Share on other sites

but when i try and compare it to my database it doesnt match

 

^^^ How do you know that?

 

And your code can be greatly simplified -

 

$string =  $n1 . $n2 . $n3 . $n4;

 

 

oh thankyou :P

 

becuase i have php code which compares it to a int in my db.

 


       if ($string == $user->nums){
  
           echo "MATCH";
           
       }

       if ($string != $user->nums){
  
           echo "NO MATCH";
           
       }

 

echoing $user->nums gives the correct value so its not that.

 

Link to comment
Share on other sites

You likely have a non-printing character stored as part of your data AND you would generally test a value in the query rather than actually retrieving the data and comparing it using some slow parsed, tokenized, interpreted php code. Your code will execute at least 10x faster.

 

Since you do have the values in php variables, use var_dump() on both of them to see what they actually contain.

Link to comment
Share on other sites

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.