oceans Posted April 25, 2007 Share Posted April 25, 2007 Dear People, May you please help me in “Check for Repeated Entry”. Situation: I have 5 TextBoxes, I need to make sure All Entries are NOT the SAME, I should be able to make my own function, but if there is such function in PHP, I can use it before sweating right. I may appear easy, to process 5 Boxes, it involves creative looping, I believe. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/ Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 $boxes = array('box1' => "$_POST['box1']", 'box2' => "$_POST['box2']", 'box3' => "$_POST['box3']", 'box4' => "$_POST['box4']", 'box5' => "$_POST['box5']"); $unique = array_unique($boxes); $count = count($unique); if($count < 5){ // this is bad }else{ //this is good } Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237728 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Dear Friend, There is a problem, My code: " $boxes = array('Txt1' => "$_POST['Txt1']", 'Txt2' => "$_POST['Txt2']", 'Txt3' => "$_POST['Txt3']", 'Txt4' => "$_POST['Txt4']", 'Txt5' => "$_POST['Txt5']"); $unique = array_unique($boxes); $count = count($unique); if($count < 5) { // this is bad echo "Reapeated Entry Found!"; { else { //this is good echo "Reapeated Entry NOT Found!"; } " error on screen " Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\MyPHP\Member\Untitled-1.php on line 68 " I believe you are using "Pointers". I am honest, I am not good at "Pointers", thus I can't understand the error either, can you help me. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237733 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Can you indicate the code from lines 65 - 70 please Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237739 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 your { is backward in { else { should be } else { Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237741 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Dear People, Thanks for the breaces: My code " <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?PHP //Transfer Data from Screen to Memory $NumberOfTxtBoxes=5; $NumberOfTxtBoxesToBeFilled=5; $theValue = "No"; if (isset($_POST['Submit'])) { for ($i=1; $i<=$NumberOfTxtBoxes; $i++) { $InputFromScreen[$i]=strtoupper($_POST["Txt".$i]); } } else { for ($i=1; $i<=$NumberOfTxtBoxes; $i++) { $InputFromScreen[$i]=""; } } $boxes = array('Txt1' => "$_POST['Txt1']", 'Txt2' => "$_POST['Txt2']", 'Txt3' => "$_POST['Txt3']", 'Txt4' => "$_POST['Txt4']", 'Txt5' => "$_POST['Txt5']"); $unique = array_unique($boxes); $count = count($unique); if($count < 5) { // this is bad echo "Reapeated Entry Found!"; } else { //this is good echo "Reapeated Entry NOT Found!"; } ?> <form id="form1" name="form1" method="post" action="Untitled-1.php"> <table width="200" border="1"> <tr> <td> </td> <td><input name="Txt1" value="<?PHP echo $InputFromScreen[1]; ?>" type="text" id="Txt1" /></td> </tr> <tr> <td> </td> <td><input name="Txt2" value="<?PHP echo $InputFromScreen[2]; ?>" type="text" id="Txt2" /></td> </tr> <tr> <td> </td> <td><input name="Txt3" value="<?PHP echo $InputFromScreen[3]; ?>" type="text" id="Txt3" /></td> </tr> <tr> <td> </td> <td><input name="Txt4" value="<?PHP echo $InputFromScreen[4]; ?>" type="text" id="Txt4" /></td> </tr> <tr> <td> </td> <td><input name="Txt33" value="<?PHP echo $InputFromScreen[5]; ?>" type="text" id="Txt33" /></td> </tr> <tr> <td> </td> <td><select name="Combo2" size="1" class="WorkPageField" id="Combo2"> <option value="Yes" <? if($theValue == "Yes"){ echo "selected"; } ?>>Yes</option> <option value="No" <? if($theValue == "No"){ echo "selected"; } ?>>No</option> </select></td> </tr> <tr> <td> </td> <td><select name="select" size="1" class="WorkPageField" id="select"> <option value="Yes">Yes</option> <option value="No">No</option> </select></td> </tr> <tr> <td> </td> <td><?PHP ?></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form> </body> </html> " Error on screen " Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\MyPHP\Member\Untitled-1.php on line 29 " Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237743 Share on other sites More sharing options...
sanfly Posted April 25, 2007 Share Posted April 25, 2007 Try replacing this part $boxes = array('Txt1' => "$_POST['Txt1']", 'Txt2' => "$_POST['Txt2']", 'Txt3' => "$_POST['Txt3']", 'Txt4' => "$_POST['Txt4']", 'Txt5' => "$_POST['Txt5']"); with this $boxes = array('Txt1' => $_POST['Txt1'], 'Txt2' => $_POST['Txt2'], 'Txt3' => $_POST['Txt3'], 'Txt4' => $_POST['Txt4'], 'Txt5' => $_POST['Txt5']); Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237748 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 yeah. prolly a quote problem Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237751 Share on other sites More sharing options...
boo_lolly Posted April 25, 2007 Share Posted April 25, 2007 the first thing that comes to mind is a nested foreach loop. <?php $bool = false; foreach($_POST as $key1 => $val1){ foreach($_POST as $key2 => $val2){ (($val1 == $val2) ? ($bool == true) : ('')); } } echo (($bool == true) ? ("this is bad.\n") : ("this is good")); ?> but i'm sure there's a much better way to do it. but that should work in the meantime. EDIT: that will not work because it will always end up comparing itself with itself, so $bool will always eventually be true. i'll edit this post with another function when i figure it out. i think you had it right with array_unique: <?php if(!array_unique($_POST)){ echo "not good.\n"; }else{ echo "this is acceptable.\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237757 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 SanFly, Thanks it works, Boo_Lolly, I had your idea in my mind "creative looping" but it is a sweat. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237765 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 no thanks needed to the guy who supplied the code... Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237770 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Dear Benjaminbeazy, I over looked, thanks for your code. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237773 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 I have another application problem for this, How can I make it ignore empty entries, if not, minimum two unfilled entries will fail the test. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237783 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 foreach($boxes as $var => $val){ if(strlen(ltrim(rtrim($val))) < 1){ echo "1 or more boxes are empty"; } } Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237787 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Dear Benjaminbeazy, I think I missleasd you. What I ment was. Situation: We have five boxes, three are filled uniquely, the other two left empty. Your code will respond all the five boxes are not unique, because of the empty boxes. How can we get arround this "inovating your code" to ignore the boxes if it is empty. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237788 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 so you want it to still be ok if 2 boxes are empty and ther other 3 are unique, right....? Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237791 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Perfect, ignore all empty entryies, take action only on those filled entries. min number of filled entry=0 max number of filled entry=5 Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237792 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 i posted the relevant code, u can replace as necessary foreach($boxes as $var => $val){ if(strlen(ltrim(rtrim($val))) < 1){ unset($boxes[$var]); } } if($count(array_unique($boxes)) < count($boxes)) { // this is bad echo "Reapeated Entry Found!"; } else { //this is good echo "Repeated Entry NOT Found!"; } Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237793 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 I tried " $boxes = array('Txt1' => $InputFromScreen[1], 'Txt2' => $InputFromScreen[2], 'Txt3' => $InputFromScreen[3], 'Txt4' => $InputFromScreen[4], 'Txt5' => $InputFromScreen[5]); foreach($boxes as $var => $val) { if(strlen(ltrim(rtrim($val))) < 1) { unset($boxes[$var]); } } if($count(array_unique($boxes)) < count($boxes)) { // this is bad echo "Reapeated Entry Found!"; } else { //this is good echo "Repeated Entry NOT Found!"; } " error on screen " Fatal error: Function name must be a string in C:\wamp\www\MyPHP\Member\Untitled-1.php on line 44 " line 44 is "if($count(array_unique($boxes)) < count($boxes))" Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237796 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 okay then assign the vars before the conditional.... $unique = array_unique($boxes); $unique = count($unique); $count = count($boxes); and change conditional to... if($unique < $count){ Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237801 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 actually my bad dont do all that, just get rid of the $ in front of count in the if statement i'm tired and not catching little junk like that.. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237802 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Splandid, Thanks a million. Link to comment https://forums.phpfreaks.com/topic/48553-solved-check-for-repeated-entry/#findComment-237812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.