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
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.
On the PHP side: