freakykiwi Posted January 4, 2007 Share Posted January 4, 2007 [code]<html><head><title> Name test </title></head><body>Hi <?php echo htmlspecialchars ($_POST['name']) ;?><p> you are <?php echo (int) $_POST['age'] ;?> years old!</p><p><?php if (strpos($_POST['name'], 'Harley') !==FLASE){echo 'Hey champ! Welcome';}else {echo 'hi Stranger/Other, how are you';}?></p></body></html>[/code]I want it to say 'Hey champ! Welcome' when Harley was inputted, but 'Hi Stranger/Other' when another name was put it. with this code 'Hi champ, Welcome' comes up for everybody~Freakykiwi Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/ Share on other sites More sharing options...
genericnumber1 Posted January 4, 2007 Share Posted January 4, 2007 Uhhhh if you're saying there is an error it would be the !== flase thing... false would be better... in fact, giving us any idea what your questions is would be better Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152580 Share on other sites More sharing options...
Philip Posted January 4, 2007 Share Posted January 4, 2007 I would be more than willing to help, but could you describe what the error is?And as genericnumber said, you need to use != FALSE not !==FLASE Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152581 Share on other sites More sharing options...
genericnumber1 Posted January 4, 2007 Share Posted January 4, 2007 !== would actually be correct, since if the string is 'Harley' it will return 0 (the index of where it starts) and if you use != it will cast 0 as false Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152584 Share on other sites More sharing options...
Philip Posted January 4, 2007 Share Posted January 4, 2007 Learn something new everyday :)Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152586 Share on other sites More sharing options...
freakykiwi Posted January 4, 2007 Author Share Posted January 4, 2007 I wasn't thinking and I'd written the post in textedit copied/pasted :SMy question was, is that I want it to say 'Hey champ! Welcome' when Harley was inputted, but 'Hi Stranger/Other' when another name was put it. with this code 'Hi champ, Welcome' comes up for everybody Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152587 Share on other sites More sharing options...
Jessica Posted January 4, 2007 Share Posted January 4, 2007 You made it more complicated than need be.[code]<?php if ($_POST['name'] == 'Harley'){ echo 'Hey champ! Welcome';}else{ echo 'hi Stranger/Other, how are you';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152589 Share on other sites More sharing options...
freakykiwi Posted January 4, 2007 Author Share Posted January 4, 2007 everything came up blank :(http://freakykiwi.ifastnet.com/form.html Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152594 Share on other sites More sharing options...
Jessica Posted January 4, 2007 Share Posted January 4, 2007 You probably have a parse error. Post the new code. Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152600 Share on other sites More sharing options...
freakykiwi Posted January 4, 2007 Author Share Posted January 4, 2007 [code]<html><head><title> Name test </title></head><body>Hi <?php echo htmlspecialchars ($_POST['name']) ;?><p> you are <?php echo (int) $_POST['age'] ;?> years old!</p><p><?php if ($_POST['name'] == 'Harley'){ echo 'Hey champ! Welcome';}else{ echo 'hi Stranger/Other, how are you';}?></p></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152623 Share on other sites More sharing options...
Jessica Posted January 4, 2007 Share Posted January 4, 2007 Try this:[code]<html><head><title> Name test </title></head><body>Hi <?=htmlspecialchars($_POST['name'])?><p> you are <?=intval($_POST['age'])?> years old!</p><p><?php if($_POST['name'] == 'Harley'){ echo 'Hey champ! Welcome';}else{ echo 'hi Stranger/Other, how are you';}?></p></body></html>[/code]It works for me. What you had already also works on my server. *shrug*. Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152629 Share on other sites More sharing options...
freakykiwi Posted January 4, 2007 Author Share Posted January 4, 2007 still didn't work.would it be something to do with linking the htmlspecialchars rather than strpos? Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152635 Share on other sites More sharing options...
tcollie Posted January 4, 2007 Share Posted January 4, 2007 Post your actual HTML from your form. Maybe you have some typos/errors in it also. Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152640 Share on other sites More sharing options...
marcus Posted January 4, 2007 Share Posted January 4, 2007 [code]<?php$name = $_POST['name'];$age = $_POST['age'];if(!is_numeric($age)){die("The age is not numeric");}if(!ctype_alnum($name)){die("Your name contained illegal characters");}echo "$name<p> you are $age years old!<br></p><p>";if($name == 'Harley'){ echo 'Hey champ! Welcome</p>';}else{ echo 'hi Stranger/Other, how are you</p>';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152644 Share on other sites More sharing options...
Jessica Posted January 4, 2007 Share Posted January 4, 2007 And you've saved that file as action.php? I've had problems in the past with error reporting and using die.Try this and see if anything shows up.Otherwise, comment everything out and add lines back in until it stops working. That will show you the problematic line.[code]if(!is_numeric($age)){print "The age is not numeric";die();}if(!ctype_alnum($name)){print "Your name contained illegal characters";die();}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152646 Share on other sites More sharing options...
freakykiwi Posted January 4, 2007 Author Share Posted January 4, 2007 comment everything? like slowly take out the stuff that isn't nessicary? how do I know what is and isnt? Quote Link to comment https://forums.phpfreaks.com/topic/32773-code-error-for-learning-sake/#findComment-152686 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.