Jump to content

Recommended Posts

ok so I have 2 files one html and one php html seems to work fine and at one point so did the php one but now when I hit summit the php shows me part of the code doesnt work properly ok here the

 

html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Example</title>
<style type="text/css">
hr {color: sienna}
p {margin-left: 20px}
body {background-image: url("images/back40.gif");font-size:16px}

h1 {margin-left: 20px;font-size:16px}
</style>

    </head>
    
    
    
    <body>
        <form action="form.php" method="POST">

<br><br>

<h1>First name:<br>
<input type="text" name="firstname">
<br><br>
Last name: <br>
<input type="text" name="lastname">
<br><br>
<font color="red">Phone Number:*</font><br>
<input type="text" name="phone">
<br><br>
<font color="red">Email:* </font><br>
<input type="text" name="email">
<br><br>
Organization:<br>
<input type="text" name="organization">
<br><br>
<font color="red">Product:*</font><br>
<select name="product">
  <option value="WIAT-II" SELECTED>WIAT-II</option>
  <option value="WAIS IV">WAIS IV</option>
</select>
<br><br>
<font color="red">Serial Number:*</font><br>
<input type="text" name="serial" >
<br><br>
<input type="submit" value="Submit" name="submit">
</h1>
</form>

    </body>
</html>

 

 

AND the PHP PARt is :

<!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>
<style type="text/css">
h1 {margin-left: 40px;font-size:16px;margin-top: 60px;text-decoration: none};
div.error {color: #ff0000};
</style></head >
<body>
<h1><?php 
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$organization = $_POST['organization'];
$serial = $_POST['serial'];
?>


<!-- First Name validation -->

<?php

if (empty ($firstname))
{	
      echo "First Name: <br/> Please enter First Name" ; 
}
else if (is_numeric($firstname))
{
        echo "First Name: <br/> Please enter a Valid First Name";
}
else 
        echo "First Name: <br/> $firstname"; 

?>
<br/><br/>

<!-- First Name validation -->


<!-- Last Name validation -->

<?php if (empty ($lastname)){
echo "First Name: <br/> Please enter Last Name" ;       
else if (is_numeric($lastname))
        echo "First Name: <br/> Please enter a Valid Last Name";
else 
        echo "First Name: <br/> $lastname";?><br/><br/>

<!-- Last Name validation -->	

<!-- Phone Number validation -->   

<?php

      if (empty ($phone))
   echo "Phone Number: <br/> Please enter Phone Number" ;       
      else if (!is_numeric($phone))
            "Phone Number: <br/> Please enter a Valid Phone Number";
      else 
             echo "Phone Number: <br/> $phone";?><br/><br/>



<!-- Phone Number validation -->  

<!-- Email validation --> 

<?php if(empty($email))
  
        echo "Email: <br/> Please enter your email address.";
    
   
    else
   
        // IF USER ENTERED AN INVALID EMAIL ADDRESS
        if(preg_match('/.*@.*\..*/',  $email) > 0)
    
            echo "Email: <br/> $email";
     
        else
       
echo "Email: <br/> Please enter a valid email address."; ?><br/><br/>

<!-- Email validation --> 


<!-- Organization validation --> 

<?php if (empty ($organization))
echo "Organization: <br/> Please enter Organization" ;       
else 
        echo "Organization: <br/> $organization";?><br/><br/>

<!-- Organization validation --> 


<?php echo " Product:<br/> {$_POST["product"]}";?><br/><br/>

<!-- Serial Number Validation --> 

<?php if (empty ($serial))
echo "Serial Number: <br/> Please enter Serial Number" ;       
else 
        echo "Serial Number:<br/> $serial";?><br/><br/>

<!-- Serial Number Validation --> 

<a href="form.html">Start Over</a></h1>
</body>
</html>

please help me I had it working and then something happened I cant figure it out

 

thanks!!

Link to comment
https://forums.phpfreaks.com/topic/132348-php-help-with-validation-of-a-form/
Share on other sites

whatever your problem, it's probably being caused by incorrect use of double quotes here:

<?php echo " Product:<br/> {$_POST["product"]}";?><br/><br/>

change that to:

<?php echo " Product:<br/> {$_POST['product']}";?><br/><br/>

(single quotes around product).

no error messages jsut after I hit the summit button on my html page and goes to the php page shows this instead of showing the info entered into the form shows me the code not the results hope someone can help me!

 

 

Please enter First Name" ; } else if (is_numeric($firstname)) { echo "First Name:

Please enter a Valid First Name"; } else echo "First Name:

$firstname"; ?>

 

Please enter Last Name" ; else if (is_numeric($lastname)) echo "First Name:

Please enter a Valid Last Name"; else echo "First Name:

$lastname";?>

 

Please enter Phone Number" ; else if (!is_numeric($phone)) "Phone Number:

Please enter a Valid Phone Number"; else echo "Phone Number:

$phone";?>

 

Please enter your email address."; else // IF USER ENTERED AN INVALID EMAIL ADDRESS if(preg_match('/.*@.*\..*/', $email) > 0) echo "Email:

$email"; else echo "Email:

Please enter a valid email address."; ?>

 

Please enter Organization" ; else echo "Organization:

$organization";?>

 

{$_POST["product"]}";?>

 

Please enter Serial Number" ; else echo "Serial Number:

$serial";?>

 

Start Over

  • 2 weeks later...

Honestly no idea what is causing the problem. Tested it with your code at my pc and it worked like a charm. (PHP 5.2.6)

 

Something similar happened once to my friend and he had to restart apache and it fixed it self.

 

One of the reasons why it would show you the code instead of result would be that its not php file but html file instead.

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.