Alecdude Posted December 26, 2008 Share Posted December 26, 2008 Here's the script: <?php $age1 = "".$_POST['Year']." = ".$_POST['Year']." - 1996"; $age2 = "".$_POST['Year']." = 1996 - ".$_POST['Year'].""; if ($_POST['Submit']) { if ($_POST['Year'] == 1996) { echo "You are the same age as me!"; } else { if ($_POST['Year'] < 1996) { echo "You are ".$age1." year(s) younger than me"; } else { echo "You are ".$age2." year(s) older than me"; } } } ?> I'm probably making a simple mistake. If anything else is needed, I will provide it. Please help. Link to comment https://forums.phpfreaks.com/topic/138484-solved-simple-math-script-not-executing-fully-not-giving-off-error/ Share on other sites More sharing options...
carrotcake1029 Posted December 26, 2008 Share Posted December 26, 2008 Your making that a bit too complicated. <?php $age = abs($_POST['Year'] - 1996); if ($_POST['Submit']) { if ($_POST['Year'] == 1996) { echo "You are the same age as me!"; } else { if ($_POST['Year'] > 1996) { echo "You are ".$age." year(s) younger than me"; } else { echo "You are ".$age." year(s) older than me"; } } } ?> Sorry had to edit, didn't fully read what you were doing, plus your logic was wrong with the less than symbol. Link to comment https://forums.phpfreaks.com/topic/138484-solved-simple-math-script-not-executing-fully-not-giving-off-error/#findComment-724061 Share on other sites More sharing options...
Alecdude Posted December 26, 2008 Author Share Posted December 26, 2008 Still doesn't work :-\ Link to comment https://forums.phpfreaks.com/topic/138484-solved-simple-math-script-not-executing-fully-not-giving-off-error/#findComment-724063 Share on other sites More sharing options...
carrotcake1029 Posted December 26, 2008 Share Posted December 26, 2008 Try this: test.php <?php $age = abs($_POST['Year'] - 1996); if ($_POST['Year'] == 1996) { echo "You are the same age as me!"; } else { if ($_POST['Year'] > 1996) { echo "You are ".$age." year(s) younger than me"; } else { echo "You are ".$age." year(s) older than me"; } } ?> test.html <form action="test.php" method='POST'> Enter the Year in which you were born<input type='text' name='Year'><br/> <input type='Submit' value='Go'><br/> </form> Link to comment https://forums.phpfreaks.com/topic/138484-solved-simple-math-script-not-executing-fully-not-giving-off-error/#findComment-724064 Share on other sites More sharing options...
Alecdude Posted December 26, 2008 Author Share Posted December 26, 2008 Thank you, that worked. And now I know about the abs function. Have a nice day! Link to comment https://forums.phpfreaks.com/topic/138484-solved-simple-math-script-not-executing-fully-not-giving-off-error/#findComment-724065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.