Marcus2000 Posted March 1, 2011 Share Posted March 1, 2011 Hi people, I really hope you guys can help me out today. I'm just a newbe at php and i'm having real trouble. Bassically all I want to do is have a user type in a company name in a html form. If what the user types in the form matches the company name in my php script i want the user to be sent to another page on my site. If what the user types in the form doesnt match the company name in my php script i want the user to be sent to a differnt page like an error page for example. this is my html form: <form id="form1" name="form1" method="post" action="form_test.php"> <p>company name: <input type="text" name="company_name" id="company_name" /> </p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> And this is the php code I'm trying to process the information on: <?php $comp_name = abc; if(isset ($_POST["company_name"])){ if($_POST["company_name"] == $comp_name){ header("Location: http://www.hotmail.com"); exit(); } else{ header("Location: http://www.yahoo.com"); exit(); } } ?> The thing is i'm getting this error when i test it: Warning: Cannot modify header information - headers already sent by (output started at D:\Sites\killerphp.com\form_test.php:10) in D:\Sites\killerphp.com\form_test.php on line 17 Please can some one help me out, i'm sure this is just basic stuff but i just cant get it to work Cheers. Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/ Share on other sites More sharing options...
Psycho Posted March 1, 2011 Share Posted March 1, 2011 Your problem is on the very first line of code $comp_name = abc; That line is trying to assign the value of a constant named abc as the value of $comp_name. I assume you mean to assign a string value of "abc". So, you need to enclose the value in quotes (either single or double) $comp_name = "abc"; EDIT: Also no need for two separate IF statements: $comp_name = "abc"; if(isset($_POST['company_name']) && $_POST['company_name']==$comp_name) { header("Location: http://www.hotmail.com"); } else { header("Location: http://www.yahoo.com"); } exit(); Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/#findComment-1181108 Share on other sites More sharing options...
Marcus2000 Posted March 1, 2011 Author Share Posted March 1, 2011 Thanks for responding to my post dude, but even with the admenments i am still getting the error message: Warning: Cannot modify header information - headers already sent by (output started at D:\Sites\killerphp.com\form_test.php:10) in D:\Sites\killerphp.com\form_test.php on line 20 I'm just not having any luck with this at all. I'm using VertrigoServ for testing the script, is there a chance that it may be an issue with that? this is the exact code i'm testing <?php $comp_name = "abc"; if(isset($_POST['company_name']) && $_POST['company_name']==$comp_name) { header("Location: http://www.hotmail.com"); } else { header("Location: http://www.yahoo.com"); } exit(); ?> Thanks for your help mate, I know I can get this, its just driving me a little insain now. Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/#findComment-1181112 Share on other sites More sharing options...
chaseman Posted March 1, 2011 Share Posted March 1, 2011 How does your Source Code look like? Make sure there's no breaking line or anything else in front of the opening PHP tag. Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/#findComment-1181130 Share on other sites More sharing options...
PaulRyan Posted March 1, 2011 Share Posted March 1, 2011 There isn't 20 lines of code present in the post that you made, which is where the error supposedly is. Are you including this file somwhere? If so, include at the very top with no spaces or outputted text above it. Also when defining variables, do your best to use single quotes, it is proven to be faster. As when using double quotes, PHP interprets the string to look for any variables present and place them within the string. Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/#findComment-1181132 Share on other sites More sharing options...
Marcus2000 Posted March 1, 2011 Author Share Posted March 1, 2011 Finally..... sucess. Cheers guys, I just removed the code above the php open tag and at the end tag and it seems to be working. Very very pleased, this is the first bit of php code that i have made that seems to work. Thank you so much for your help people. Will be back soon i'm sure, with loads more quetsions. Cheers. Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/#findComment-1181137 Share on other sites More sharing options...
murray price Posted July 24, 2012 Share Posted July 24, 2012 How would I modify this script so someone is sent to a success page if they enter any 1 of 100 postal codes that I add into the script or a fail page if a postal code they enter is not listed in the script? Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/#findComment-1364010 Share on other sites More sharing options...
PFMaBiSmAd Posted July 24, 2012 Share Posted July 24, 2012 You need to start your own thread for your question. If you need to reference an existing thread, put a link to that thread in your post. Locking this thread... Link to comment https://forums.phpfreaks.com/topic/229223-text-input-correct-go-to-one-page-text-input-incorrect-go-to-another-page/#findComment-1364015 Share on other sites More sharing options...
Recommended Posts