Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
submit error PHP web form self submit?
Old 07-08-2011, 10:22 AM submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
Hey i want to make a web form for my web i am trying this code but it do nothing. i cant get where is error in this script please help me.

PHP Code:
<html>
<body bgcolor="silver" text="blue" link="black">

<form action="" method="post">
    <table align="center">
        <tbody align="left" valign="top">
        <tr>
        <td height="100"></td>
        </tr>
        <tr>
            <td>
                Name:* </td>
            <td>
                <input type="text" name="Name" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                E-Mail:* </td>
            <td>
                <input type="text" name="E_Mail" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                Phone no:* </td>
            <td>
                <input type="text" name="Ph" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                Ga: </td>
            <td>
                <input type="text" name="Ga" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                Comments:* </td>
            <td>
                <textarea rows="3" cols="20" name="Comments"></textarea>
            </td>
        </tr>
        <tr>
            <td>
            * Required
            </td>
        </tr>
    </table>
    <table align="center">
        <tr>
            <td>
                <input type="submit" value="Submit" alt="submit" name="submit" />
            </td>
            <td>
                <input type="reset" />
            </td>
        </tr>
    </table>
</form>

</body>
</html>
<?php
    
if (isset($POST["submit"]))
    {
        include(
"data.php");
        
$Name=$_POST['Name'];
        
$E_Mail=$_POST['E_Mail'];
        
$Ph=$_POST['Ph'];
        
$Ga=$_POST['Ga'];
        
$Comments=$_POST['Comments'];
        
        if (
$Name == '' || $E_Mail == '' || $Ph == '' || $Comments == '')
            {
                
$error 'true';
 
                echo 
"ERROR: Please fill required fields!";
            }
        else
            {
                
$error 'false';
            }
            
        if(
preg_match("/^[+]{1}[0-9]{12}$/"$Ph)) {
            
$error 'true';
            echo 
"The Phone number is not valid.";
        }
        else
        {
            
$error 'false';
        }
                
        if(
preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/"$E_Mail)) {
            
$error 'true';
            echo 
"Your Email is not Valid.";
        }
        else
        {
            
$error 'false';
        }
        if(
$error == "true")
        {
            echo 
"There is an error";
        }
        else
        {
            
mysql_query("INSERT INTO `gmifamil_form`.`gmi` (Name, EMail, Ph, Ga, Comments) VALUES ('$Name', '$E_Mail', '$Ph', '$Ga', '$Comments')")
            or die(
mysql_error());
            
header("Location: th.htm");
        }
        
    }

?>

Last edited by DezineGenerators; 07-08-2011 at 10:36 AM..
DezineGenerators is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-08-2011, 10:27 AM Re: submit error PHP web form self submit?
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
When posting code make sure to use the php tags. Otherwise all of the formatting is lost. See the 'how to post code' link in my sig.

At first glance there are two things I noticed that are wrong. First:
PHP Code:
if (isset($POST["submit"])) 
should be
PHP Code:
if (isset($_POST["submit"])) 
notice the underscore ( _ ).

Second, you're calling header after you've already sent output. You should do your form processing before you output your form. This will resolve the header issue and also allow you to display error messages in the form if needed.

Edit
Forgot to mention, you're also wide open for a SQL injection.

Other than that you'll have to clarify and post any error message you're getting.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 07-08-2011 at 10:37 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-08-2011, 10:32 AM Re: submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
now when i click on submit with out any entry i redirect to th.htm without any error. i dnt want empty entries
DezineGenerators is offline
Reply With Quote
View Public Profile
 
Old 07-08-2011, 10:41 AM Re: submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
As you can see that i have generated errors for empty variables but when i submit this form without any text i don't get any error.
DezineGenerators is offline
Reply With Quote
View Public Profile
 
Old 07-08-2011, 10:42 AM Re: submit error PHP web form self submit?
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by DezineGenerators View Post
now when i click on submit with out any entry i redirect to th.htm without any error. i dnt want empty entries
I'm guessing it's because you're setting $error to false in multiple cases. Set $error to false initially and then set it to true if there is a problem. By the way, you don't need to quote booleans.
PHP Code:
$error "true"//wrong
$error true//right 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-08-2011, 10:43 AM Re: submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
sorry i cant under stand you please can you give me any example of processin.
DezineGenerators is offline
Reply With Quote
View Public Profile
 
Old 07-08-2011, 10:46 AM Re: submit error PHP web form self submit?
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
For example:
PHP Code:
if(isset($_POST['submit']))
{
     
$error false;

     if (
$Name == '' || $E_Mail == '' || $Ph == '' || $Comments == '')
     {
          
$error true;
 
           echo 
"ERROR: Please fill required fields!";
     }
     
//leave off the else case

Once $error is set to false you shouldn't set it to false again.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-08-2011, 10:54 AM Re: submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
I am getting same problem empty entries on submit
DezineGenerators is offline
Reply With Quote
View Public Profile
 
Old 07-08-2011, 10:57 AM Re: submit error PHP web form self submit?
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
Can you post the code you're using now?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-08-2011, 11:17 AM Re: submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
Here it is
PHP Code:
<html>
<body bgcolor="silver" text="blue" link="black">

<form action="" method="post">
    <table align="center">
        <tbody align="left" valign="top">
        <tr>
        <td height="100"></td>
        </tr>
        <tr>
            <td>
                Name:* </td>
            <td>
                <input type="text" name="Name" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                E-Mail:* </td>
            <td>
                <input type="text" name="E_Mail" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                Phone no:* </td>
            <td>
                <input type="text" name="Ph" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                Ga: </td>
            <td>
                <input type="text" name="Ga" value="" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                Comments:* </td>
            <td>
                <textarea rows="3" cols="20" name="Comments"></textarea>
            </td>
        </tr>
        <tr>
            <td>
            * Required
            </td>
        </tr>
    </table>
    <table align="center">
        <tr>
            <td>
                <input type="submit" value="Submit" alt="submit" name="submit" />
            </td>
            <td>
                <input type="reset" />
            </td>
        </tr>
    </table>
</form>

</body>
</html>
<?php
    
if (isset($_POST["submit"]))
    {
        include(
"data.php");
        
$Name=$_POST['Name'];
        
$E_Mail=$_POST['E_Mail'];
        
$Ph=$_POST['Ph'];
        
$Ga=$_POST['Ga'];
        
$Comments=$_POST['Comments'];
        
        
$error flase;
        
        if (
$Name == '' || $E_Mail == '' || $Ph == '' || $Comments == '')
            {
                
$error true;
 
                echo 
"ERROR: Please fill required fields!";
            }
        else
            {
                
$error false;
            }
            
        if(
preg_match("/^[+]{1}[0-9]{12}$/"$Ph)) {
            
$error true;
            echo 
"The Phone number is not valid.";
        }
        else
        {
            
$error false;
        }
                
        if(
preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/"$E_Mail)) {
            
$error true;
            echo 
"Your Email is not Valid.";
        }
        else
        {
            
$error false;
        }
        if(
$error == true)
        {
            echo 
"There is an error";
        }
        else
        {
            
mysql_query("INSERT INTO `gmifamil_form`.`gmi` (Name, EMail, Ph, Ga, Comments) VALUES ('$Name', '$E_Mail', '$Ph', '$Ga', '$Comments')")
            or die(
mysql_error());
            
header("Location: th.htm");
        }
        
    }

?>
DezineGenerators is offline
Reply With Quote
View Public Profile
 
Old 07-08-2011, 11:20 AM Re: submit error PHP web form self submit?
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
You only need to set $error to false once. Once it is true, you should never set it to false again.

Remove all of the else conditions:
PHP Code:
else
{
     
$error false;

Also there is an error here:
PHP Code:
$error flase
"flase" should be false.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-08-2011, 11:26 AM Re: submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
Ok thans for this now it shows empty error but mail validation and ph no validation is not working.
DezineGenerators is offline
Reply With Quote
View Public Profile
 
Old 07-08-2011, 03:22 PM Re: submit error PHP web form self submit?
Average Talker

Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
Trades: 0
I am still having problem with this code.
Warning: Cannot modify header information - headers already sent by (output started at /home/contact.php) in /home/contact.php on line 43
PHP Code:
<?php
    
if (isset($_POST["submit"]))
    {
        include(
"data.php");
        
$Name=$_POST['Name'];
        
$E_Mail=$_POST['E_Mail'];
        
$Ph=$_POST['Ph'];
        
$Ga=$_POST['Ga'];
        
$Comments=$_POST['Comments'];
        
$head false;
        
$error false;
        
        if (
$Name == '' || $E_Mail == '' || $Ph == '' || $Comments == '')
            { 
                echo 
'<div id="container"><div style="position:absolute;left:500px;top:237px;width:768px;height:23px;z-index:10" align="left">Write your name.</div><div style="position:absolute;left:540px;top:335px;width:768px;height:23px;z-index:10" align="left">Your comments Please!</div></div>';
            }
        if(
preg_match("/^[+]{1}[0-9]{12}$/"$Ph)) {
            
$error false;
        }
        else{
            
$error true;
            echo 
'<div id="container"><div style="position:absolute;left:500px;top:287px;width:768px;height:23px;z-index:10" align="left">Please Write your no in this formet (+011231231234)</div></div>';
        }
                        
        if(
preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/"$E_Mail)) {
            
$error false;
        }
        else{
            
$error true;
            echo 
'<div id="container"><div style="position:absolute;left:500px;top:263px;width:768px;height:23px;z-index:10" align="left">Email adress is not Valid.</div></div>';
        }
        
        if(
$error == false){
            
$head true;
            
mysql_query("INSERT INTO `gmifamil_form`.`gmi` (Name, EMail, Ph, Ga, Comments) VALUES ('$Name', '$E_Mail', '$Ph', '$Ga', '$Comments')")
            or die(
mysql_error());
                        
        }
        
    }
    if(
$head == true){
            
header("Location: Thank_you.htm");
        }
?>
DezineGenerators is offline
Reply With Quote
View Public Profile
 
Old 07-09-2011, 04:05 AM Re: submit error PHP web form self submit?
chrishirst's Avatar
Defies a Status

Posts: 44,055
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You cannot redirect once output has been sent to the user agent.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to submit error PHP web form self submit?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40507 seconds with 11 queries