A.White.89 Posted February 18, 2009 Share Posted February 18, 2009 Here is what I have: ask.php <?php if($_POST['user'] && $_POST['email'] && $_POST['rockdoc'] != "null" && $_POST['comments']){ processForm(); } else{ print '<font color="red" size="3"><b>Please complete every field in the form</font></b><br/>'; print showForm(); } //Send form to e-mail function processForm(){ print "Hello, " . $_POST['user']; } function showForm(){ $form = '<form method="POST" action="$_SERVER[\'PHP_SELF\']"> Name: <input type="text" name="user"><br/><br/> E-mail: <input type="text" name="email"><br/><br/> RockDoctor: <select name="rockdoc"> <option value="null"></option> <option value="voice">Voice</option> <option value="guitar">Guitar</option> <option value="drums">Bass Drums</option> <option value="keys">Keys</option> <option value="engineering">Engineering</option> <option value="health">Health</option> <option value="management">Management</option> <option value="legal">Legal</option> </select><br/><br/> Comments, Concerns, Requests: <br/> <textarea name="comments" rows="10" cols="75" ></textarea><br/><br/> <input type="submit" value="Submit to RockDoctor"> </form>'; return $form; } ?> To get to this php file, there is a html form with method="post" action="ask.php" The php is run correctly when the fields are invalid, but then if the form is run again, I get the following error: Not Found The requested URL /PHP_Practice/$_SERVER['PHP_SELF'] was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Does anyone know why this happens? Thanks Link to comment https://forums.phpfreaks.com/topic/145682-solved-using-a-form-in-php/ Share on other sites More sharing options...
trq Posted February 18, 2009 Share Posted February 18, 2009 This.... '<form method="POST" action="$_SERVER[\'PHP_SELF\']"> should be.... '<form method="POST" action="' . $_SERVER['PHP_SELF'] . "> or simply.... '<form method="POST" action=""> Link to comment https://forums.phpfreaks.com/topic/145682-solved-using-a-form-in-php/#findComment-764848 Share on other sites More sharing options...
angelcool Posted February 18, 2009 Share Posted February 18, 2009 i'll say you have a path issue in: action="ask.php" Link to comment https://forums.phpfreaks.com/topic/145682-solved-using-a-form-in-php/#findComment-764849 Share on other sites More sharing options...
A.White.89 Posted February 18, 2009 Author Share Posted February 18, 2009 Thanks, the latter worked with action="". The second one didn't work. Have a nice night Link to comment https://forums.phpfreaks.com/topic/145682-solved-using-a-form-in-php/#findComment-764856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.