Mod-Jay Posted March 30, 2011 Share Posted March 30, 2011 Okay the problem is that it wont find the correct carrier. it dont even find it. i dont know whats wrong. Please take a look at the code. i dont know how to explain it better $carriers = array('verizon'=>'@vtext.com','tmobile'=>'@tomomail.com','sprint'=>'@messaging.sprintpcs.com','att'=>'@txt.att.net','virgin'=>'@vmobl.com','textnow'=>'@textnow.me','metro'=>'@mymetropcs.com','unknown'=>'@teleflip.com'); if (array_key_exists($carrier, $carriers)) { $correctCarrier = $carriers[$carrier]; $i = 0; While($i < $_POST['amount']) { $i++; $formatted_number = $to.$correctCarrier; $result = ("$i of Your Messages Has been sent to the number ". $_POST['to'] . ".<br>" . mail("$formatted_number", "$subject", "$message") . ""); } mysql_query("INSERT INTO `msgssent` (`number`, `numberofmsg`, `subject`, `message`) VALUES ('". $formatted_number ."', '". $i ."', '". $subject ."', '". $message ."')") Or die(mysql_error()); Echo $result; } Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/ Share on other sites More sharing options...
KevinM1 Posted March 30, 2011 Share Posted March 30, 2011 Where is $carrier set? Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194004 Share on other sites More sharing options...
Mod-Jay Posted March 30, 2011 Author Share Posted March 30, 2011 Upper part of the code, It gets the carrier but it doesnt find it in the array. Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194009 Share on other sites More sharing options...
ngreenwood6 Posted March 30, 2011 Share Posted March 30, 2011 does it hit inside of the loop...try putting an echo statement at the beginning of the if statement...also are you sure that $carrier is the value you are expecting...you might wanna try echoing it as well. Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194010 Share on other sites More sharing options...
Skewled Posted March 30, 2011 Share Posted March 30, 2011 if (array_key_exists($carrier, $carriers)) { CorrectCarrier = $carriers[$carrier]; At the top of your php file you are setting an array in $carriers but your saying array_key_exsist($carrier... so where are you setting your array keys in $carrier, because as it stands now you're basically looking for a key that is NULL in your $carriers array. so maybe this would do it: $carrier = array_values($carriers); if (array_key_exists($carrier, $carriers)) { CorrectCarrier = $carriers[$carrier]; I'm still working on array's so this may not be correct but hey I'm giving it a shot! Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194020 Share on other sites More sharing options...
Mod-Jay Posted March 30, 2011 Author Share Posted March 30, 2011 Actually the code i have works fine. I found the problem by echoing the 2. It actually doesnt put the number together, On the variable formatted Number, Is there a correct way of doing it? Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194021 Share on other sites More sharing options...
ngreenwood6 Posted March 30, 2011 Share Posted March 30, 2011 Maybe you should clarify better because I am confused as to what you are talking about. However, I did notice that you have a variable you are using as $to but do not see it set anywhere and somewhere else you use $_POST['to']. Is the $to supposed to be $_POST['to']? Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194025 Share on other sites More sharing options...
Mod-Jay Posted March 30, 2011 Author Share Posted March 30, 2011 its set above all that Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194030 Share on other sites More sharing options...
Mod-Jay Posted March 30, 2011 Author Share Posted March 30, 2011 Also everytime i send something it leaves a '1' at the end of the message. 1 of Your Messages Has been sent to the number ***.1 , idk why its doing it though Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194041 Share on other sites More sharing options...
trq Posted March 30, 2011 Share Posted March 30, 2011 Also everytime i send something it leaves a '1' at the end of the message. 1 of Your Messages Has been sent to the number ***.1 , idk why its doing it though Because your concatenating a call to the mail() function onto the end of your $result string and mail() is returning true (1). Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194042 Share on other sites More sharing options...
Mod-Jay Posted March 30, 2011 Author Share Posted March 30, 2011 How do i fix it? Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194054 Share on other sites More sharing options...
trq Posted March 30, 2011 Share Posted March 30, 2011 Move the call to mail() out of your echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194057 Share on other sites More sharing options...
Mod-Jay Posted March 30, 2011 Author Share Posted March 30, 2011 how will i fix it? Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194070 Share on other sites More sharing options...
trq Posted March 30, 2011 Share Posted March 30, 2011 Move the call to mail() out of your echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/232121-php-array-problem/#findComment-1194077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.