seany123 Posted October 19, 2010 Share Posted October 19, 2010 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 https://forums.phpfreaks.com/topic/216304-help-with-making-string-from-values/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2010 Share Posted October 19, 2010 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; Link to comment https://forums.phpfreaks.com/topic/216304-help-with-making-string-from-values/#findComment-1124137 Share on other sites More sharing options...
seany123 Posted October 19, 2010 Author Share Posted October 19, 2010 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 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 https://forums.phpfreaks.com/topic/216304-help-with-making-string-from-values/#findComment-1124140 Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2010 Share Posted October 19, 2010 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 https://forums.phpfreaks.com/topic/216304-help-with-making-string-from-values/#findComment-1124148 Share on other sites More sharing options...
seany123 Posted October 19, 2010 Author Share Posted October 19, 2010 the db var dump returned NULL... wtf i dont understand how thats possible. Link to comment https://forums.phpfreaks.com/topic/216304-help-with-making-string-from-values/#findComment-1124152 Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2010 Share Posted October 19, 2010 Your code probably has an error in it somewhere. Link to comment https://forums.phpfreaks.com/topic/216304-help-with-making-string-from-values/#findComment-1124156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.