mellowmuppet Posted February 14, 2008 Share Posted February 14, 2008 I am trying to do some 'simple' validation: This is the code i am useing <form action="" method="get"> <p>Please enter your name, </p><input type="text" name="name" /> <?php if (empty($_GET['name'])) { echo "You must enter your name<" } ?> //Some code emitted (same as above basically) <input type="Submit" /> </form> If you look at the code it should, when nothing is put in the form flag up an error and display the text. it only displays a blank page though which is frustrating. Im fairly new to php and my lecturers code doesnt work either. I use a Xampp setup and its all up and running and am configuring with notepad ++ After doing this i need to make sure that its > 3 characters but < 15 how would i implement this into the code on the same page. Should i create a seperate .php page which does tihs part and leave the validation on the html form? Thanks MM (edited by kenrbnsn to add tags for better readability) Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/ Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 Turn on error reporting so it returns errors echo "You must enter your name<" should be echo "You must enter your name"; Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466740 Share on other sites More sharing options...
micah1701 Posted February 14, 2008 Share Posted February 14, 2008 if you're posting this form you need to use $_POST['name'] not $_GET['name'] EDIT: I withdraw my response, as I see you're setting the method to "get" you are missing a colon after your echo statement though (as revraz pointed out) Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466741 Share on other sites More sharing options...
mellowmuppet Posted February 14, 2008 Author Share Posted February 14, 2008 echo "You must enter your name<" is supposed to be echo "You must enter your name</body></html>"; i think but i have updated the code for that Im simply trying to create a form that will validate the information in that page before i take them to another page. unless the requirements are met it will return an error message on the same page and ask the user to correct so the field must have some data and this data must be within the range of 3 - 15 characters long Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466746 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 If you don't want a blank page, as stated, turn on error reporting in your php.ini or using ini_set Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466752 Share on other sites More sharing options...
mellowmuppet Posted February 14, 2008 Author Share Posted February 14, 2008 I dont understand how to do that >.< Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466755 Share on other sites More sharing options...
aschk Posted February 14, 2008 Share Posted February 14, 2008 Like this: <?php // Set up error reporting. error_reporting(E_ALL); ini_set("display_errors","2"); ?> put it at the top of ALL your code. Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466759 Share on other sites More sharing options...
mellowmuppet Posted February 14, 2008 Author Share Posted February 14, 2008 I give up. no errors are being returned so im just going to ignore it. <?php // Set up error reporting. error_reporting(E_ALL); ini_set("display_errors","2"); ?> no errors reported thanks for your help though. ive been pissing around with this for like 3 hours now an im just getting really angry all i have to do is the following. Produce a PHP page that validates data entered in the field. You should at a very minimum validate presence, length and range. It just wont do what its told. funny im stuck on this cause ive done all the other stuff with SQLyog apache and everything. jsut really winds me up hence why i should never be a programmer Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466763 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 Does a simple page like <?php echo "hi"; ?> work? Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466767 Share on other sites More sharing options...
mellowmuppet Posted February 14, 2008 Author Share Posted February 14, 2008 yeh ive been writing code all day. just this is code is being a prick. i did test the simple code though lol Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466769 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 Try these examples http://www.w3schools.com/php/php_forms.asp Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466774 Share on other sites More sharing options...
mellowmuppet Posted February 14, 2008 Author Share Posted February 14, 2008 thx Link to comment https://forums.phpfreaks.com/topic/91066-real-problems/#findComment-466781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.