PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mikeeeeeeey
Forum Contributor
Posts: 130 Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK
Post
by mikeeeeeeey » Mon Jan 21, 2008 8:49 am
Hi,
I have some lines of code...
Code: Select all
$percent = (int)$_POST['search_factor'];
$sum = round($colour+($colour/$percent));
which generates the warning...
Code: Select all
Warning: Division by zero in C:\wamp\.....
and I'm too sure why. If I change $percent to a number e.g. 10, it works fine. Can anyone please help?
Thanks
Last edited by
mikeeeeeeey on Mon Jan 21, 2008 11:04 am, edited 1 time in total.
Inkyskin
Forum Contributor
Posts: 282 Joined: Mon Nov 19, 2007 10:15 am
Location: UK
Post
by Inkyskin » Mon Jan 21, 2008 8:52 am
Try echoing the value of $_POST['search_factor'] first, to make sure it actually has a number in it
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Mon Jan 21, 2008 8:53 am
What are you trying to achieve?
There are 10 types of people in this world, those who understand binary and those who don't
mikeeeeeeey
Forum Contributor
Posts: 130 Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK
Post
by mikeeeeeeey » Mon Jan 21, 2008 8:57 am
If I do a var_dump() of $_POST['search_factor'], it says it is an integer, so if the number was 10 it would output...
and I'm trying to get a user-inputted percentage, then generate two other numbers; (using the example percentage above)
number-(10% of number)
and
number+(10% of number)
Tor Vidvei
Forum Newbie
Posts: 2 Joined: Mon Jan 21, 2008 10:00 am
Post
by Tor Vidvei » Mon Jan 21, 2008 10:26 am
mikeeeeeeey wrote:
...and I'm trying to get a user-inputted percentage, then generate two other numbers; (using the example percentage above)
number-(10% of number)
and
number+(10% of number)
Shouldn't you then write
Code: Select all
$sum = round($colour+($colour*$percent));
instead of the cited code? (Then your problem vanishes...)
Tor Vidvei
mikeeeeeeey
Forum Contributor
Posts: 130 Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK
Post
by mikeeeeeeey » Mon Jan 21, 2008 11:04 am
Oh yeah! Thanks for your help