Hi I'm very new to php and just learning.
I have this form in html and corresponding php code that work fine after getting help here. But I'm going in circles to know how and where to introduce code to make some fields as required fields.
I looked up several examples and 'm not sure if they are asking me to create another php file or should I insert another php block in this code or?????? ... Can you please help me with a simple solution? Thanks in advance.
HTML FORM CODE
<html>
<Table align="center">
<tr>
<td>
<h2> Sign Up Form</h2>
<form action="signup_insert.php" method="POST" id="insert" name="signup">
<Table align="center">
<tr>
<td > First Name*</td>
<td ><input type="text" size=40 name="fname"></td>
</tr>
<tr>
<td > Last Name*</td>
<td ><input type="text" size=40 name="lname"></td>
</tr>
<tr>
<td >Email*</td>
<td ><input type="text" size=40 name="email"></td>
</tr>
<tr>
<td >Gender</td>
<td > <input type="radio" name="likeit" value="Yes" checked="checked" /> Yes <input type="radio" name="likeit" value="No" /> No </td>
</tr>
<tr>
<td >Address1</td>
<td ><input type="text" size=40 name="address1"></td>
</tr>
<tr>
<td >Address2</td>
<td ><input type="text" size=40 name="address2"></td>
</tr>
<tr>
<tr>
<td >City</td>
<td> <select name="city">
<option>Timbaktoo</option>
</select>
</td>
</tr>
<tr>
<td >State</td>
<td> <select name="state">
<option>Lala Land</option>
</select>
</td>
</tr>
<tr>
<td >Postal Code</td>
<td ><input type="text" size=40 name="zipcode"></td>
</tr>
<tr>
<td >User Name*</td>
<td ><input type="text" size=40 name="username" value="useremail id captured from email box above"></td>
</tr>
<tr>
<td >Password*</td>
<td ><input type="password" size=40 name="password"> <font color="red"> (Must contain atleast 6 characters with one Upper case letter and one number)</font></td>
</tr>
<tr>
<td >Security Question*</td>
<td> <select name="securityq">
<option>What is your mother's maiden name ?</option> </select>
</td>
</tr>
<tr>
<td >Security Answer*</td>
<td ><input type="text" size=40 name="securitya"> </td>
</tr>
<tr>
<td colspan=2 id="sub"> <input name="log" type="button" value="Submit" onclick="document.signup.submit(); document.signup.reset();">
<input type="reset" name="reset" value="Reset" > </td>
</tr>
<tr>
</tr>
</Table>
</tr>
</td>
</form>
</Table>
</body>
</html>
In the above form I'm trying to get 1. some fields to be required, else throe error mssg.,
2. Populate the username field with the value of the email field above and then grey out, 3. Get the form to reset after submit without having to click the reset button. These rae the areas I'm having issues. My values are getting into the databse fine.
The php code I'm using has no code for the 3 items above as I'm at aloss to understand and 'm getting confused as I read more on the internet without hand holding as explained above,please help. Thanks.
PHP code
<?php
$username="abcd@@@####";
$password="Lalagulubulu";
$database="abcd@@@####";
$fname=isset($_POST['fname']) ? $_POST['fname'] : NULL;
$lname=isset($_POST['lname']) ? $_POST['lname'] : NULL;
$email=isset($_POST['email']) ? $_POST['email'] : NULL;
$gender=isset($_POST['gender']) ? $_POST['gender'] : NULL;
$address1=isset($_POST['address1']) ? $_POST['address1'] : NULL;
$address2=isset($_POST['address2']) ? $_POST['address2'] : NULL;
$city=isset($_POST['city']) ? $_POST['city'] : NULL;
$state=isset($_POST['state']) ? $_POST['state'] : NULL;
$pincode=isset($_POST['pincode']) ? $_POST['pincode'] : NULL;
$username=isset($_POST['username']) ? $_POST['username'] : NULL;
$password=isset($_POST['password']) ? $_POST['password'] : NULL;
$securityq=isset($_POST['securityq']) ? $_POST['securityq'] : NULL;
$securitya=isset($_POST['securitya']) ? $_POST['securitya'] : NULL;
mysql_connect("abcd@@@####.db.12345678.temptingforceource.com","abcd@@@####","Lalagulubulu");
mysql_select_db("abcd@@@####") or die("Unable to select database");
$query = "INSERT INTO refuser VALUES
('','$fname','$lname','$email','$gender','$address1','$address2','$city','$state','$zipcodecode','$username','$password','$securityq','$securitya')";
mysql_query($query);
echo $query;
echo "Data entered successfully";
?>