Jump to content
xisto Community
eddygalvin

Php Code Error need help on this code

Recommended Posts

hello need a bit of help on this code, it give an 'insufficient units to send sms.'

<?include "igwt.php";include "mysql.php";include "../../api/smsapi.php";session_start(); $message = $_POST[message];$to = $_POST[receiver];$from = $_POST[from];/* if (strlen($to) == 10){$error[] = "You have to specify the country code, too. Eg. 13333333333";} */if ($_SESSION['username'] == ''){include "loginerror.php";die;exit;break;}$check = mysql_query("SELECT name, firstname, active, sms FROM users WHERE username = '$username'");$row = mysql_fetch_row($check); $_SESSION['name'] = $row[0];$_SESSION['firstname'] = $row[1]; $_SESSION['active'] = $row[2];$_SESSION['sms'] = $row[3];$_SESSION['username'] = $username;$left = $_SESSION['sms'];$on = $_SESSION['active']; // check the mobile number$atom = '[-a-z!#$%&\'*+/=?^_`{|}~]';if (eregi($atom, $to)) { $error[] = 'Invalid mobile phone number';}if ($left == '0'){$error[] = 'Not enough SMS credits to deliver this message.';}if (empty ($to)) {        	$error[] = 'You not specify destination address (TO)!';    	}if (empty ($from)) {    	    $error[] = 'You have not specified any sender id!';    	}if (strlen ($message) > 465) {			$error[] = 'Your message is too long';			}if ($on == 'no'){$error[] = 'Your account status is not active.';}if ((strlen ($message)) <= 160) {                    $balance = 1;                 } else { //greater than 160                    $count = ((strlen ($message)) / 153);                 if ($count <= 3 && $count >2) {					$balance = 3;					}				if ($count <= 2 && $count >1) {					$balance = 2;								}				if ($count <= 4 && $count >3) {					$balance = 4;					}			}			$recipients = explode(",", $to);$cost = count($recipients) * $balance;    	if ($cost > $left) {    		$error[] = 'insufficient units to send sms.';			}						if (!$error){mysql_query("UPDATE users SET sms = sms-'$cost' WHERE username = '$username'");$tudei = date('Y-m-d');mysql_query("INSERT INTO sms (username, message, date, tono, fromno) VALUES('".$username."','".$message."','".$tudei."','".$to."','".$from."')") or die(mysql_error());$mysms = new sms();$results = $mysms->send($to,$from,$message);}echo $sus;?>

Notice from rvalkass:

All code needs to have code tags around it.

Share this post


Link to post
Share on other sites

This section of code generates the error you are talking about:

if ($left == '0'){$error[] = 'Not enough SMS credits to deliver this message.';}

As you can see, that error is triggered when the variable $left is set to 0. Working back up the code we find these lines:

$check = mysql_query("SELECT name, firstname, active, sms FROM users WHERE username = '$username'");$row = mysql_fetch_row($check); $_SESSION['name'] = $row[0];$_SESSION['firstname'] = $row[1]; $_SESSION['active'] = $row[2];$_SESSION['sms'] = $row[3];$_SESSION['username'] = $username;$left = $_SESSION['sms'];$on = $_SESSION['active'];

So $left is set from the 'sms' column in the database. Presumably on the row you are using the value for 'sms' is zero. Have a look in the database and check what the value is.

Share this post


Link to post
Share on other sites

thanks, but the value of the sms colume is set to 1 on the database.
i think this aspect of the scripts generates the error

"$recipients = explode(",", $to);$cost = count($recipients) * $balance;    	if ($cost > $left) {    		$error[] = 'insufficient units to send sms.';			}"

Share this post


Link to post
Share on other sites

Before the if statement triggering that error, echo out the values of $to, $recipients, $cost, $balance and $left. That should help you narrow down where the problem is occurring.

Share this post


Link to post
Share on other sites

There doesn't seem to be a problem with the assignment operations for $recipients and $cost. Look up the values for $to, $balance, and $left. Try XDebug - it's a pretty good free debugger that works with Eclipse (or NuSphere, NetBeans or any other PHP IDE).

thanks, but the value of the sms colume is set to 1 on the database. i think this aspect of the scripts generates the error

"$recipients = explode(",", $to);
$cost = count($recipients) * $balance;
if ($cost > $left) {
$error[] = 'insufficient units to send sms.';
}"


Share this post


Link to post
Share on other sites

hello i have tried downloading XDEBUGGER please i need help on how to install it. i use windows xp. all that is contained in the software is some zipped file. do i need to install the binaries on my system or on the server?.


There doesn't seem to be a problem with the assignment operations for $recipients and $cost. Look up the values for $to, $balance, and $left. Try XDebug - it's a pretty good free debugger that works with Eclipse (or NuSphere, NetBeans or any other PHP IDE).


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.