Jump to content

Recommended Posts

right i have this code below...

if (isset($_POST['username']) && ($_POST['Mamount']) && ($_POST['Msubmit'])) {

$query = $db->execute("select `id`, `username`, `money`, `gang_id` from `players` where `username` like '$username'");

    if ($query->recordcount() == 0) {
    	$errmsg .= "This player doesn't exist!<p />";
        $error = 1;
    } else if ($Mamount <= "0") {
        $errmsg .= "You cannot send this amount of money!<p />";
        $error = 1;
    } else if (!is_numeric($Mamount)) {
        $errmsg .= "You cannot send this amount of money!<p />";
        $error = 1;      
    } 
else if (isset($_POST['Mamount']) < $gang['money'])
{
$errmsg .= "You cannot send this amount of Money!<p />";
        $error = 1; 
}
else {
        $member = $query->fetchrow();
        	if ($member['gang_id'] != $gang['id']) {
    			$errmsg .= "The player $username doesn't exist in the gang " . $gang['name'] ."!<p />";
    			$error = 1;
        	} 
		else
		{
		if (isset($_POST['Mamount']) >= $gang['money'])
		{	
            	$query = $db->execute("update `gangs` set `money`=? where `id`=?", array($gang['money'] - $Mamount, $player->gang_id));
            	$query1 = $db->execute("update `players` set `money`=? where `username`=?", array($member['money'] + $Mamount, $member['username']));
            	$logmsg = "You were given <b>$" . number_format($Mamount) . "</b> money from <b>". $gang['name'] ."</b>.";
			addlog($member['id'], $logmsg, $db);
			$msg .= "You have transferred <b>" . number_format($Mamount) . "</b> points to <b>$username</b>.<p />";
        	}
    	}
}
}

 

The problem im having is with these lines...

 

else if (isset($_POST['Mamount']) < $gang['money'])
{
$errmsg .= "You cannot send this amount of Money!<p />";
        $error = 1; 
}

 

 

i have $gang['money'] echo'd and currently its at -500... so everything this line is run it should give that $errmgs but for some reason its not.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/161307-help/
Share on other sites

If by straight after your elseif you mean this

 

    } else if ($Mamount <= "0") {
        $errmsg .= "You cannot send this amount of money!<p />";

then it wont work.

 

Your script is attempting string concatenation on a varialbe that doesn't yet exist.

 

Get rid of the dots;

 

$errmsg = "You cannot send this amount of money!<p />"

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851216
Share on other sites

If by straight after your elseif you mean this

 

    } else if ($Mamount <= "0") {
        $errmsg .= "You cannot send this amount of money!<p />";

then it wont work.

 

Your script is attempting string concatenation on a varialbe that doesn't yet exist.

 

Get rid of the dots;

 

$errmsg = "You cannot send this amount of money!<p />"

 

i dont understand why thats needed... the problem im having is the fact that even though that if statement is true, its just bypassing it and running the queries below and may i add echoing $msg.

 

and $msg happens to be..

 

$msg .= "You have transferred <b>" . number_format($Mamount) . "</b> points to <b>$username</b>.<p />";

 

thats the first time $msg is set and it echo's fine with the "."

 

 

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851485
Share on other sites

try this,

 

<?php
if (isset($_POST['username']) && ($_POST['Mamount']) && ($_POST['Msubmit'])) {

$query = $db->execute("select `id`, `username`, `money`, `gang_id` from `players` where `username` like '$username'");

if ($query->recordcount() == 0) {
	$errmsg .= "This player doesn't exist!<p />";
	$error = 1;
} else if ($_POST['Mamount'] <= 0) {
	$errmsg .= "You cannot send this amount of money!<p />";
	$error = 1;
} else if (!is_numeric($_POST['Mamount'])) {
	$errmsg .= "You cannot send this amount of money!<p />";
	$error = 1;     
} else if (isset($_POST['Mamount']) < $gang['money']) {
	/**
	 * WHERE IS $gang['money'] set??
	 */
	$errmsg .= "You cannot send this amount of Money!<p />";
	$error = 1;
} else {
	$member = $query->fetchrow();
	if ($member['gang_id'] != $gang['id']) {
		$errmsg .= "The player $username doesn't exist in the gang " . $gang['name'] ."!<p />";
		$error = 1;
	} else {
		if (isset($_POST['Mamount']) >= $gang['money']) {   
			$query = $db->execute("update `gangs` set `money`=? where `id`=?", array($gang['money'] - $Mamount, $player->gang_id));
			$query1 = $db->execute("update `players` set `money`=? where `username`=?", array($member['money'] + $Mamount, $member['username']));
			$logmsg = "You were given <b>$" . number_format($Mamount) . "</b> money from <b>". $gang['name'] ."</b>.";
			addlog($member['id'], $logmsg, $db);
			$msg .= "You have transferred <b>" . number_format($Mamount) . "</b> points to <b>$username</b>.<p />";
		}
	}
}
}

 

And check the note I made on line 17

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851491
Share on other sites

$gang['money'] is in a include at the top of the page, heres the $gang bit..

 

$query = $db->execute("select * from gangs where `id`= $player->gang_id");
$gang = $query->fetchrow();

 

now i want to point out that i have $gang['money'] being echo'd on this page and they are working fine.

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851498
Share on other sites

And what about the code I posted, did it work? If no what's happening now?

 

 

nothing different happens its still just going past that if statement and doing this..

 

if (isset($_POST['Mamount']) >= $gang['money']) {   
			$query = $db->execute("update `gangs` set `money`=? where `id`=?", array($gang['money'] - $Mamount, $player->gang_id));
			$query1 = $db->execute("update `players` set `money`=? where `username`=?", array($member['money'] + $Mamount, $member['username']));
			$logmsg = "You were given <b>$" . number_format($Mamount) . "</b> money from <b>". $gang['name'] ."</b>.";
			addlog($member['id'], $logmsg, $db);
			$msg .= "You have transferred <b>" . number_format($Mamount) . "</b> points to <b>$username</b>.<p />";

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851503
Share on other sites

No its the isset

else if (isset($_POST['Mamount']) < $gang['money'])

should be

else if (isset($_POST['Mamount']) && $_POST['Mamount'] < $gang['money'])

 

EDIT: lol what joel24 said

 

i changed that.. and its still not working...

 

the queries are still running and $msg is still being echo'd

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851583
Share on other sites

basically what im trying to do is make it so...

 

 

if $gang['money'] >= $Mamount...

 

then to show a error message and not run any queries ($errmsg)

 

 

else if $gang['money'] < $Mamount

 

then to run the queries and echo $msg.

 

 

so why would i need to update the $Mamount? its always echoing the correct figure...

 

why would i need to change the other messages?....

 

its echoing the $msg (which is the sucess message) meaning that none of the failsafes worked.

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851616
Share on other sites

Read back and learn how to fix it as its been explained already!

 

 

no all that has been posted about that is changing

 

else if (isset($_POST['Mamount']) < $gang['money'])

 

to

 

else if (isset($_POST['Mamount']) && $_POST['Mamount'] < $gang['money'])

 

which is what i have already done.

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851635
Share on other sites

I said

Read back and learn how to fix it as its been explained already!

 

this code doesn't make sense!

if (isset($_POST['Mamount']) >= $gang['money'])

 

as joel24 pointed out with another line!

else if (isset($_POST['Mamount']) < $gang['money'])

 

wouldn't that line be returning

if (true/false < $gang['money'] ???

 

change it to

else if (isset($_POST['Mamount']) and $_POST['Mamount'] < $gang['money']) ...

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851639
Share on other sites

It's a different if statment, and can be fixed the same way you fixed the other.

 

else if (isset($_POST['Mamount']) < $gang['money'])

was changed to

 

else if (isset($_POST['Mamount']) && $_POST['Mamount'] < $gang['money'])

so;

 

if (isset($_POST['Mamount']) >= $gang['money'])

should be changed to...

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851640
Share on other sites

i have already had that done.

 

 

if (isset($_POST['username']) && ($_POST['Mamount']) && ($_POST['Msubmit'])) {

$query = $db->execute("select `id`, `username`, `money`, `gang_id` from `players` where `username` like '$username'");

if ($query->recordcount() == 0) {
	$errmsg .= "This player doesn't exist!<p />";
	$error = 1;
} else if ($_POST['Mamount'] <= 0) {
	$errmsg .= "You cannot send this amount of money!<p />";
	$error = 1;
} else if (!is_numeric($_POST['Mamount'])) {
	$errmsg .= "You cannot send this amount of money!<p />";
	$error = 1;     
}
else if (isset($_POST['Mamount']) && $_POST['Mamount'] < $gang['money'])
{
	/**
	 * WHERE IS $gang['money'] set??
	 */
	$errmsg .= "You cannot send this amount of Money!<p />";
	$error = 1;
} 
else 
{
	$member = $query->fetchrow();
	if ($member['gang_id'] != $gang['id']) {
		$errmsg .= "The player $username doesn't exist in the gang " . $gang['name'] ."!<p />";
		$error = 1;
	} else 
	{
		if (isset($_POST['Mamount']) && $_POST['Mamount'] >= $gang['money'])
		{   
			$query = $db->execute("update `gangs` set `money`=? where `id`=?", array($gang['money'] - $Mamount, $player->gang_id));
			$query1 = $db->execute("update `players` set `money`=? where `username`=?", array($member['money'] + $Mamount, $member['username']));
			$logmsg = "You were given <b>$" . number_format($Mamount) . "</b> money from <b>". $gang['name'] ."</b>.";
			addlog($member['id'], $logmsg, $db);
			$msg .= "You have transferred <b>" . number_format($Mamount) . "</b> points to <b>$username</b>.<p />";
		}
	}
}
}

Link to comment
https://forums.phpfreaks.com/topic/161307-help/#findComment-851642
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.