Solved

required fields in PHP

Posted on 2007-04-05
10
224 Views
Last Modified: 2007-04-06
Can somebody tell me whats wrong with this PHP. Everytime I hit on submit on my HTML page it takes me no where. It does not do what its supposed to do. I am pasting my HTML and PHP file which its calling

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Please enter the requested infor</title>
</head>

<body bgcolor="#FFCC99">
<form action="formhandler.php" method="POST">
<p>Please enter the requested information.
</p>

<table style="width:240px" border="0">
  <tr>
    <td style="width:62px">Name:</td>
    <td><input name="name" size="30"></td>
  </tr>
  <tr>
    <td style="width:62px">Spouse Name:</td>
    <td><input name="spousename" size="30"></td>
  </tr>
  <tr>
    <td style="width:62px">Address1:</td>
    <td><input name="Address1" size="30"></td>
  </tr>
<tr>
    <td style="width:62px">Address2:</td>
    <td><input name="Address2" size="30"></td>
  </tr>
<tr>
    <td style="width:62px">City:</td>
    <td><input name="city" size="30"></td>
  </tr>
<tr>
    <td style="width:62px">State:</td>
    <td><input name="state" size="5"></td>
  </tr>
<tr>
    <td style="width:62px">Zip:</td>
    <td><input name="zip" size="11"></td>
  </tr>

  <tr>
    <td>Email:</td>
    <td><input name="email" size = "30"></td>
  </tr>
  <tr>
    <td>Phone:</td>
    <td><input name="phone" size="16"></td>
  </tr>

</table>
<br>
&nbsp;</br>
  <input type="submit" value="Send">
  <input type="reset" value="Clear the form">

</form>
</body>
</html>



PHP

<?php
$errorMsg = '';
$name = $_POST['name'];
if ($name=="") {
   errorMsg .= "Then name is required.
}
$sname = $_POST['spousename'];
$ad1 = $_POST['Address1'];
if ($ad1=="") {
   errorMsg .= "Then address is required.
}

$ad2 = $_POST['Address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];

if ($errorMsg=='') {
    $message = "Name: $name\n";
    $message .= "Spouse Name: $spousename\n";
    $message .= "Address1: $address1\n";
    $message .= "Address2: $address2\n";
    $message .= "City: $city\n";
    $message .= "State: $state\n";
    $message .= "Zip: $zip\n";
    $message .= "Email: $email\n";
    $message .= "Phone: $phone\n";

    if (!mail('myemailid@yahoo.com','From Website',$message)) die('Mail Failed!');
    header("Location: http://www.yahoo.com");
    exit();
} else {
    echo $errorMsg . "<a href=\"prevpage\">Go Back</a>";
}
?>
0
Comment
Question by:pratikshahse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 14

Expert Comment

by:Vel Eous
ID: 18859231
$errorMsg = '';
$name = $_POST['name'];
if (empty($name)) {
   errorMsg .= "Then name is required.
}
$sname = $_POST['spousename'];
$ad1 = $_POST['Address1'];
if (empty($ad1)) {
   errorMsg .= "Then address is required.
}

$ad2 = $_POST['Address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];

if (empty($errorMsg)) {
    $message = "Name: $name\n";
    $message .= "Spouse Name: $spousename\n";
    $message .= "Address1: $address1\n";
    $message .= "Address2: $address2\n";
    $message .= "City: $city\n";
    $message .= "State: $state\n";
    $message .= "Zip: $zip\n";
    $message .= "Email: $email\n";
    $message .= "Phone: $phone\n";

    if (!mail('myemailid@yahoo.com','From Website',$message)) die('Mail Failed!');
    header("Location: http://www.yahoo.com");
    exit();
} else {
    echo $errorMsg . "<a href=\"prevpage\">Go Back</a>";
}
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18859336
The following lines aren't properly closed. They should like what I put below.

  errorMsg .= "Then name is required.";
   errorMsg .= "Then address is required.";
0
 

Author Comment

by:pratikshahse
ID: 18859733
Its not working. No matter what I do, whether I put in the information and hit submit or if i dont put in infomation , it still takes me nowhere. you can check out  what I am trying to say

www.jcoco.org/new_member.htm

click on submit without entering any info and click on submit after entering info.

if there is no info entered then i want the error to show up saying required fields are required and if the info is filled in then take me back to home page and also e mail me with the info entered.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18860553
If you echo some text at the top of the php file, does it show up?

Just wondering, as you are right, absolutely nothing came back
0
 

Author Comment

by:pratikshahse
ID: 18860598
Nope. nothing comes up.

0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18860686
Somehow that file isn't being updated or has the wrong permissions.

does it has the same permissions as the html? Depending on your server, it may need the execute attribute.

chmod +x filename
0
 

Author Comment

by:pratikshahse
ID: 18860740
it should have the same permissions as I have on html as I have  another PHP file and I am sure i did not change any security on that file and still it runs ok.
0
 
LVL 14

Accepted Solution

by:
raja_ind82 earned 500 total points
ID: 18860946
required.php
********************************************
<?php
if(isset($_POST['hdnvalue']) && $_POST['hdnvalue']=="send")
{
$name = $_POST['firstname'];  
$sname = $_POST['spousename'];
$ad2 = $_POST['Address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];


$message = "Name: $name\n";
$message .= "Spouse Name: $spousename\n";
$message .= "Address1: $address1\n";
$message .= "Address2: $address2\n";
$message .= "City: $city\n";
$message .= "State: $state\n";
$message .= "Zip: $zip\n";
$message .= "Email: $email\n";
$message .= "Phone: $phone\n";

@mail('myemailid@yahoo.com','From Website',$message);
header("Location: index.php");
exit;
}

?>

<head>
<title>Please enter the requested infor</title>
<script>
function funcheck() {
 
  with(document.frmname)
  {
       if((firstname.value)=="")
        {
           alert("Please enter the name.");
             firstname.focus();return false;
        }
       else if((spousename.value)=="")
        {
           alert("Please enter the spousename.");
             spousename.focus();return false;
        }
        else
        {      
              hdnvalue.value="send";
              submit();
 
        }
  }
}
</script>
</head>

<body bgcolor="#FFCC99">
<form action="required.php" method="POST" name="frmname">
<input type="hidden" name="hdnvalue">
<p>Please enter the requested information.
</p>

<table style="width:240px" border="0">
  <tr>
    <td style="width:62px">Name:</td>
    <td><input name="firstname" size="30"></td>
  </tr>
  <tr>
    <td style="width:62px">Spouse Name:</td>
    <td><input name="spousename" size="30"></td>
  </tr>
  <tr>
    <td style="width:62px">Address1:</td>
    <td><input name="Address1" size="30"></td>
  </tr>
<tr>
    <td style="width:62px">Address2:</td>
    <td><input name="Address2" size="30"></td>
  </tr>
<tr>
    <td style="width:62px">City:</td>
    <td><input name="city" size="30"></td>
  </tr>
<tr>
    <td style="width:62px">State:</td>
    <td><input name="state" size="5"></td>
  </tr>
<tr>
    <td style="width:62px">Zip:</td>
    <td><input name="zip" size="11"></td>
  </tr>

  <tr>
    <td>Email:</td>
    <td><input name="email" size = "30"></td>
  </tr>
  <tr>
    <td>Phone:</td>
    <td><input name="phone" size="16"></td>
  </tr>

</table>
<br>
&nbsp;</br>
  <input type="button" value="Send" name="btnsubmit" onclick="javascript: funcheck();">
  <input type="reset" value="Clear the form">

</form>
</body>
</html>

index.php
***********************
<?php  
echo "index PAGE";
?>
Regards,
M.Raja
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18861016
Is the other PHP file in the same directory as this one? I would still look at the permissions to verify them.

If that is good, I'm not sure whats going on. I am getting nothing when accessing the file, no errors, nothing.

0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18861070
Wow, Raja rewrote the whole thing for you!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Make check boxes work 8 47
Modify Filter to cause a field to be not Required 3 30
How to remove  "0":  in a json string 4 17
JSON decode 5 21
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Common practice undertaken by most system administrators is to document the configurations and final solutions of anything performed by them for their future use and reference. So here I am going to explain how to export ISA Server 2004 Firewall pol…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question