seany123 Posted June 7, 2009 Share Posted June 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/ Share on other sites More sharing options...
gevans Posted June 7, 2009 Share Posted June 7, 2009 Where do you echo $errmsg, and where do you initially set it? You need something like this before you try and concat anything to the varable; $errmsg = NULL; Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851201 Share on other sites More sharing options...
seany123 Posted June 7, 2009 Author Share Posted June 7, 2009 im setting $errmsg straight after the else if... then echoing it further down my script... <p /><font color=yellow><?=$msg?></font><p /> <p /><font color=red><?=$errmsg?></font> Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851205 Share on other sites More sharing options...
gevans Posted June 7, 2009 Share Posted June 7, 2009 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 />" Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851216 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 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 "." Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851485 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851491 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851498 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 And what about the code I posted, did it work? If no what's happening now? Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851499 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 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 />"; Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851503 Share on other sites More sharing options...
joel24 Posted June 8, 2009 Share Posted June 8, 2009 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']) ... Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851566 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851571 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851583 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 Well you have that exact message 3 times are adding numbers to them to workout the exact line also whats $_POST['Mamount'] & $gang['money'] set to ? Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851590 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 i have $gang['money'] echo'd its currently 10 $_POST['Mamount'] is whatever i set the number in the form to... 11+ Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851596 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 In that case the line thats causing the problem isn't that one did you change the other messages and update the $Mamount ? Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851611 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851616 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 you mean ONE of the fail safes failed! which would be this one if (isset($_POST['Mamount']) >= $gang['money']) Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851623 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 you mean ONE of the fail safes failed! which would be this one if (isset($_POST['Mamount']) >= $gang['money']) well its if (isset($_POST['Mamount']) && $_POST['Mamount'] < $gang['money']) now. Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851630 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 Read back and learn how to fix it as its been explained already! Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851632 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851635 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 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']) ... Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851639 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851640 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 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 />"; } } } } Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851642 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 Was their a question ? Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851662 Share on other sites More sharing options...
seany123 Posted June 8, 2009 Author Share Posted June 8, 2009 well can you see anything else wrong with this script... like i said i have already changed the if statements so they work... but its still not working. Quote Link to comment https://forums.phpfreaks.com/topic/161307-help/#findComment-851666 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.