Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7518239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:43:25+00:00 2026-05-30T01:43:25+00:00

I realize there are similar threads regarding .asp pages, however I am using an

  • 0

I realize there are similar threads regarding .asp pages, however I am using an html form with php involved with the submit action leading into a survey.

The client I am developing for would like either one of the text fields to be filled out, while neither one is hard required one of the two must be filled out. It can be either of the two, however both cannot be left blank.

I would prefer to not use jquery, however if this is necessary I will learn how. I am brand new to all of this and just creating the form and connecting it to the database took a whole lot of learning lol.

Thank you for any help, below I have posted the HTML form, and the php script it is linked to.

<form action="insert.php" method="post">
Name: <input type="varchar" name="name" />
<span style="color: #F00">or</span> Email:
<input type="varchar" name="email" />
<input type="submit" />
</form>

The PHP ‘insert.php

<?php
$con = mysql_connect("localhost","gobagtoo_1","1");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("gobagtoo_1", $con);

$sql="INSERT INTO name_email (name, email)
VALUES
('$_POST[name]','$_POST[email]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else 
$url = 'tool.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';  

mysql_close($con)
?>

M

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:43:25+00:00Added an answer on May 30, 2026 at 1:43 am

    You should accomplish this both on the client side (where you see the form) with javascript and on the server side (the PHP after you submit the form).

    On the client side:
    1. Add the function to the page, validateForm.
    2. Add id attributes to your name and email elements.
    3. Add an onsubmit element to your form tag.

        <html>
        <head>
        <script language="javascript">
        function validateForm(){
            var value1 = document.getElementById('nameId').value;
            var value2 = document.getElementById('emailId').value;
            if( value1 != "" || value2 != "" ) 
            {
                return true;    
            }
            alert("You must enter a value");
            return false;
        }
        </script>
        </head>
    
        <body>
        <form action="insert.php" method="post" onsubmit="return validateForm();">
        Name: <input type="text" name="name" id="nameId" /> 
        <span style="color: #F00">or</span> Email: <input type="text" name="email" id="emailId" />
        <input type="submit" /> 
        </form> 
        </body>
        </html>
    

    On the PHP side:

        <?PHP
    
        function makeSafeish( $value ){
            return mysql_escape_real_string( $value );
            // If you put this in a function, you can do more w/ it. I don't use this as is but don't want to be judged by the community here for my bad use :P
        }
    
        if( strlen( $_POST['name'] ) > 0 && strlen( $_POST['email'] ) > 0 ){
            $con = mysql_connect("localhost","******","******"); 
            if (!$con) { 
                die('Could not connect: ' . mysql_error()); 
            }  
            mysql_select_db("*****", $con); 
            $sql="INSERT INTO name_email (name, email) VALUES ('".makeSafeish( $_POST["name"] )."','".makeSafeish( $_POST["email"] )."')"; 
            if ( ! mysql_query( $sql, $con ) ) { 
                die('Error: ' . mysql_error()); 
            } else  {
                $url = 'tool.html'; 
            }
    
            echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';    
            mysql_close($con); // you're not gonna get here because of the above line.
        }else{
            echo 'You must enter either an email or name.";
        }
        ?> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize there are similar questions but only regarding saving files on Linux servers
I realize there are similar questions on this topic, but I still cannot find
I know there a similar threads around, but this is really the first time
I realize there are tonnes of similar questions already up here but I cannot
I realize that, generally speaking, there are performance implications of using reflection. (I myself
I realize that there are many questions similar to this one, but having looked
I realize there are similar questions on SO, but they don't quite solve my
I realize that there have been similar questions, but they seem to have been
Similar to __callee__ , is there something which returns the calling method? I realize
I realize that there are similar questions , but my question is slightly different:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.