SergeantFlash Posted August 11, 2008 Share Posted August 11, 2008 I have this code inside a php file and I was wondering if I wrote it the right way, since I'm not quite sure how to check the opposite of something (like a Boolean - true/false): if (! @is_numeric($pkills)) { echo( "$pkills is an improper value for kills"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/ Share on other sites More sharing options...
wildteen88 Posted August 11, 2008 Share Posted August 11, 2008 Yes that is correct. is_numeric returns true or false and ! means NOT. Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/#findComment-613521 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Why do you have the @ there? Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/#findComment-613522 Share on other sites More sharing options...
SergeantFlash Posted August 11, 2008 Author Share Posted August 11, 2008 okay, thanks Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/#findComment-613591 Share on other sites More sharing options...
PHPTOM Posted August 11, 2008 Share Posted August 11, 2008 Wouldn't this be a bit better coding? if (!is_numeric($pkills)) { die ($pkills." is an improper value for kills"); } Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/#findComment-613630 Share on other sites More sharing options...
Jabop Posted August 11, 2008 Share Posted August 11, 2008 ^^ maybe he just wants to echo it and continue the script execution. so, no. ps, dark finally got an avatar! Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/#findComment-613633 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Accomplishes the same thing. But you don't always want to kill the script for something like that (especially a form). That was directed at the thread starter btw. P.S: I finally got around to making an avatar for this forum. Wonderful, right? xD EDIT: Someone noticed. Sick. Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/#findComment-613635 Share on other sites More sharing options...
SergeantFlash Posted August 11, 2008 Author Share Posted August 11, 2008 Thanks again, I'm very knew to PHP so I'm not sure about to best practices for writing the code. The code is just for a small game I'm making with Flash CS3, when the game ends, the user can submit their score (after writing their name), and I just want to make sure the data received by the php script for kills is actually a numeric string and hasn't been tampered with. So, obviously, if the data for kills isn't actually a number, then I want the script to stop and not insert the data into my database table (mySQL). Quote Link to comment https://forums.phpfreaks.com/topic/119150-solved-simple-noob-question/#findComment-614055 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.