Jump to content

[SOLVED] Using a form in PHP


A.White.89

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.