Solved

required fields in PHP

Posted on 2007-04-05
10
226 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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