Jump to content

error checking code


mindapolis

Recommended Posts

Hi, I wrote a simple code to check to see if the user filled in the name field, but when I uploaded the file, it just displays the code.  here 's the code. 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$errors=array(); 
if(isset($_POST['submit']))
{
	validate_input(); 
	if(count($errors) !=0)
	{
		display_form(); 	
	}
	else 
	{
		display_form(); 	
	}
}
function validate_input() {
	global $errors; 
	if($_POST['name'] == " "){
	$errors['name']="dipshit, put your name";
	}
?>   
<form action="" method="post" name="test">
Name:  <input name="name" type="text" size="10" maxlength="15" value="<?php echo $_POST[name]; ?>"/><br />  
<?php echo $errors['name']; ?>
<input name="submit" type="button" value="submit" />
</form>
</body>
</html>

Link to comment
Share on other sites

when I click view source I get this code.  here 's the link to the page.  http://auntievics.com/error.phtml

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$errors=array(); 
if(isset($_POST['submit']))
{
	validate_input(); 
	if(count($errors) !=0)
	{
		display_form(); 	
	}
	else 
	{
		display_form(); 	
	}
}
function validate_input() {
	global $errors; 
	if($_POST['name'] == " "){
	$errors['name']="dipshit, put your name";
	}
?>   
<form action="" method="post" name="test">
Name:  <input name="name" type="text" size="10" maxlength="15" value="<?php echo $_POST[name]; ?>"/><br />  
<?php echo $errors['name']; ?>
<input name="submit" type="button" value="submit" />
</form>
</body>

</html>

 

Link to comment
Share on other sites

In my PHP class my professor said php and phtml were the same thing

 

your professor must of fort, when you load php from scratch, the extension settings are set as phtml and not .php

 

when you download a copy of php, sometimes the extension settings are set to all sorts of settings.

 

maybe the professor,  should teach the internal settings of php and Apache.

 

also looking at your code, i think if the teacher used upper case, for xhtml then others can identify html from php quicker.

 

also where the comments to show what the code doing.

 

If your going to learn php, html, mysql, and ajax and JavaScript plus css, might as well do it Wright.

 

what the course price dont tell me £3.ooo plus only 10 sittings/lessons

 

 

 

 

 

 

Link to comment
Share on other sites

Your professor seems like 75% of the 'teachers' I had going through my degree. The only thing harder than putting up with their classes was trying to get my money back ;)

 

To solve you issue, no PHTML is NOT the same extension as PHP. Just like <? is not the same as <?php.

Some PHP installs are set up to only parse files with the PHP extension, some will even parse HTML extensions. There are ways around this, but as a general rule, name your files using the 'php' extension to ensure maximum compatibility.

 

Let us know what happens after you change the file's extension.

Link to comment
Share on other sites

I changed  the file extension & adjusted the following code but still no go.

 

 

<?php
$errors=array(); 
if(isset($_POST['submit']))
{
	validate_input(); 
	if(count($errors) !=0)
	{
		display_form(); 	
	}
	else 
	{
		display_form(); 	
	}
}
function validate_input() {
	global $errors; 
	if(empty($_POST['name']) == " "){
	$errors['name']="Hey dipshit, put your name";
	}
	}
?>   
<form action="checkOut.php" method="post" name="test">
Name:  <input name="name" type="text" size="10" maxlength="15" value="<?php echo $_POST[name]; ?>"/><br />  
<?php echo $errors['name']; ?>
<input name="submit" type="button" value="submit" />
</form>

Link to comment
Share on other sites

No go what?

 

The PHP still isn't being parsed?

 

Are you trying to open these files on your local computer? If so, it isn't getting parsed because you don't have a parser on your computer.

Download and install WAMP (Windows) or MAMP (OSX) to solves that issue. When it's installed and running, put your PHP files in your web directory and access through http://localhost/file.php

Link to comment
Share on other sites

I won't even mess with your function attempt but here's a working form based on what you have started.  You should read up on html and forms.  Don't use type="button"...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php 
$errors=array(); 
if(isset($_POST['submit']))
{
if(empty($_POST['name'])){
$errors['name']="dipshit, put your name";
}
}
?>   
<form action="" method="post" name="test">  
<?php if(isset($errors['name'])){ echo $errors['name']."<br />"; } ?>
Name:  <input name="name" type="text" size="10" maxlength="15" value="<?php if(isset($_POST['name'])){ echo "$_POST[name]"; } ?>" /><br />  
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.