Insert Data from a dynamic registration form with radio buttons [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to insert data to my database from a form and when i select a type (doctor or patient) to send the data to the appropriate table.
HERE IS THE CODE
<?php
include_once 'header.php';
if (isset($_SESSION['username'])) destroySession();
if(isset($_POST['register']))
{
if (isset($_POST['username']))
{
$fname = sanitizeString($_POST['fname']);
$lname = sanitizeString($_POST['lname']);
$username = sanitizeString($_POST['username']);
$email = sanitizeString($_POST['email']);
$password = sanitizeString($_POST['password']);
if($_POST["answer" === "Doctor"])
{
$DoctorG = sanitizeString($_POST['DoctorG']);
$DoctorAge = ($_POST['DoctorAge']);
$specialty = sanitizeString($_POST['specialty']);
$Doctor_ID = ($_POST['Doctor_ID']);
if (mysql_num_rows(queryMysql("SELECT * FROM doctor
WHERE username='$username'")))
$error = "That username already exists<br /><br />";
else
{
queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$DoctorID')");
die("<h4>Account created</h4>Please Log in.<br /><br />");
}
}
}
}
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<form method="post" action="signup.php">
<fieldset>
<legend>Registration Form</legend>
<label>First Name
<input type="text" name="fname" required="required" />
</label>
<br/>
<br/>
<label>Last Name
<input type="text" name="lname" required="required" />
</label>
<br />
<br />
<label>Username
<input type="text" name="username" required="required" />
</label>
<br />
<br />
<label>Email
<input type="text" name="email" required="required" />
</label>
<br />
<br />
<label>Password
<input type="text" name="password" required="required" />
</label>
<br/><br/>
User Type:
<br/>Doctor
<input type="radio" name="answer" value="Doctor" />
Patient
<input type="radio" name="answer" value="Patient" />
<!--DOCTOR OPTIONS -->
<div id="expandDoctor" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="DoctorG" value="male" id="DoctorG">
<label id="Female">Female</label>
<input type="radio" name="DoctorG" value="female" id="DoctorG">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="DoctorAge" id="DoctorAge" />
<br/>
<br/>
<label id="Specialty">Specialty:</label>
<select id="SelectSpecialty" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="ID">Doctor ID:</label>
<input type="text" name="Doctor_ID" id="Doctor_ID" />
</div>
<!--PATIENT OPTIONS -->
<div id="expandPatient" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="PatientG" value="male" id="PatientGM">
<label id="Female">Female</label>
<input type="radio" name="PatientG" value="female" id="PatientGF">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="PatientAge" id="PatientAge" />
<br/>
<br/>
<label id="Disease">Disease:</label>
<select id="SelectDisease" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="SPID">SPID:</label>
<input type="text" name="PatientSPID" id="PatientSPID" />
</div>
</fieldset>
<input type="submit" value="Register" name="register"/>
</form>
</body>
<script>
$("input[type='radio'][name='answer']").change(function() {
$("[id^=expand]").hide();
$("#expand" + $(this).val()).show();
});</script>
</body>
</html>
I get this error Notice: Undefined offset: 0 in E:\xampp\htdocs\ptixiaki\signup.php on line 21
PS: I dont have all the needed inserts , I just want to test it for the Doctor and if it works for them I will do for the patient also

The error was that i should have if( $_POST["answer"] === "Doctor" ) instead of if($_POST["answer" === "Doctor"]) and then it shows a second error in the INSERT INTO which was an underscore in the Doctor_ID
HERE IS THE NEW CODE....
<?php
/**
* #author Nick Bourlai
* #copyright 2014
*/
include_once 'header.php';
if (isset($_SESSION['username'])) destroySession();
if(isset($_POST['register']))
{
if (isset($_POST['username']))
{
$fname = sanitizeString($_POST['fname']);
$lname = sanitizeString($_POST['lname']);
$username = sanitizeString($_POST['username']);
$email = sanitizeString($_POST['email']);
$password = sanitizeString($_POST['password']);
if( $_POST["answer"] === "Doctor" )
{
$DoctorG = sanitizeString($_POST['DoctorG']);
$DoctorAge = ($_POST['DoctorAge']);
$specialty = sanitizeString($_POST['specialty']);
$Doctor_ID = ($_POST['Doctor_ID']);
if (mysql_num_rows(queryMysql("SELECT * FROM doctor
WHERE username='$username'")))
$error = "That username already exists<br /><br />";
else
{
queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$Doctor_ID')");
die("<h4>Account created</h4>Please Log in.<br /><br />");
}
}
}
}
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<form method="post" action="signup.php">
<fieldset>
<legend>Registration Form</legend>
<label>First Name
<input type="text" name="fname" required="required" />
</label>
<br/>
<br/>
<label>Last Name
<input type="text" name="lname" required="required" />
</label>
<br />
<br />
<label>Username
<input type="text" name="username" required="required" />
</label>
<br />
<br />
<label>Email
<input type="text" name="email" required="required" />
</label>
<br />
<br />
<label>Password
<input type="text" name="password" required="required" />
</label>
<br/><br/>
User Type:
<br/>Doctor
<input type="radio" name="answer" value="Doctor" />
Patient
<input type="radio" name="answer" value="Patient" />
<!--DOCTOR OPTIONS -->
<div id="expandDoctor" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="DoctorG" value="male" id="DoctorG">
<label id="Female">Female</label>
<input type="radio" name="DoctorG" value="female" id="DoctorG">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="DoctorAge" id="DoctorAge" />
<br/>
<br/>
<label id="Specialty">Specialty:</label>
<select id="SelectSpecialty" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="ID">Doctor ID:</label>
<input type="text" name="Doctor_ID" id="Doctor_ID" />
</div>
<!--PATIENT OPTIONS -->
<div id="expandPatient" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="PatientG" value="male" id="PatientGM">
<label id="Female">Female</label>
<input type="radio" name="PatientG" value="female" id="PatientGF">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="PatientAge" id="PatientAge" />
<br/>
<br/>
<label id="Disease">Disease:</label>
<select id="SelectDisease" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="SPID">SPID:</label>
<input type="text" name="PatientSPID" id="PatientSPID" />
</div>
</fieldset>
<input type="submit" value="Register" name="register"/>
</form>
</body>
<script>
$("input[type='radio'][name='answer']").change(function() {
$("[id^=expand]").hide();
$("#expand" + $(this).val()).show();
});</script>
</body>
</html>

Related

Created simple HTML form with PHP, but won't POST email and opens blank page

I created the following HTML and PHP documents. When I fill in the information and click submit, I don't receive any errors, but I get a blank page and also don't receive an email with the form information. I'm fairly new at this, but could use the help on why I'm not getting the email and how to get rid of the blank page. Thank you.
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<div id="title">
<div id="titlecontact">
<h1>Excelerate Growth, LLC</h1>
<h4><em>Consulting to Help Small Businesses Excel</em></h4>
</div>
</div>
<header id="header">
<nav class="links" style="--items: 5;">
Home
About
Services
Results
Contact
<span class="line"></span>
</nav>
</header>
<?=$thankYou ?>
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
<div id="social">
<img class="linkedin" src="linkedin.png">
<img class="email2" src="email.png">
<img class="facebook" src="facebook.png">
<br/>
<br/>
</div>
<br/>
<br/>
<?php
if($_POST["submit"]) {
$recipient="jscotty78#gmail.com";
$subject="Form to email message";
$sender=$_POST["sender"];
$senderEmail=$_POST["senderEmail"];
$senderPhone=$_POST["senderPhone"];
$type=$_POST["type"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\nPhone: $senderPhone\nType: $type\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
?>
Try This Code Below with name="submit"
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" name="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
POST form data is sent using name => value. Here:
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
you have no input with name="submit". This is why $_POST['submit'] is equal to "", which is considered false in PHP. So mail() is not running.
Instead, try this:
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
<input type="hidden" name="submit" value="a" />
</form>
Notice name="submit". This gets sent along with the form data.

Mandatory fields in the html form using PHP PDO

I have a html form where i want 3 fields to be mandatory. If the user doesn't fill any one of those fields, then the form shouldn't be submitted and it should tell the user to fill in the mandatory one's. I've used PDO and i dont know how to do it. If someone could help me. Down below i've given both my html and php files.
HTML:
<html>
<head>
<title>Data Insertion</title>
</head>
<body>
<p><span class="Error">* required field.</span></p>
<form method="post" action="su.php">
<h2>Please Fill In Details</h2>
<label for="name">Name </label>
<input type="text" Placeholder="Enter your name" name="name" id="name" />
<span class="Error">*</span>
<br />
<br />
<label for="age">Age </label>
<input type="text" name="age" id="age" placeholder="Enter your age" />
<br />
<br />
<label for="mailid">MailId </label>
<input type="text" name="mailid" id="mailid" placeholder="Enter your Mail Id" />
<span class="Error">*</span>
<br />
<br />
<label for="gender">Gender </label>
<br />
<label for="male">Male </label>
<input type="radio" name="gender" id="gender" value="Male" id="male" />
<label for="female">Female </label>
<input type="radio" name="gender" id="gender" value="Female" id="female" />
<br />
<br />
<label for="qualification">Qualification </label>
<select name="qualification" value="Qualification" id="qualification">
<option value="B.E">SSLC</option>
<option value="P.G">HSC</option>
<option value="SSLC">UG</option>
<option value="HSC">PG</option>
</select>
<br /><br />
<label for="hobbies">Hobbies </label>
<br />
<input type="checkbox" name="hobbies" id="hobbies" value="Cricket" />Cricket
<input type="checkbox" name="hobbies" id="hobbies" value="Music" />Music
<input type="checkbox" name="hobbies" id="hobbies" value="Swimming" />Swimming
<br /><br />
<label for="textarea">Address </label>
<br />
<textarea name="address" id="textarea" rows="15" cols="30"></textarea>
<span class="Error">*</span>
<br /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
PHP:
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
try {
$conn = new PDO("mysql:host=$servername;dbname=testing", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['submit'])){
$name = $_POST['name'];
$age = $_POST['age'];
$mailid = $_POST['mailid'];
$gender = $_POST['qualification'];
$hobbies = $_POST['address'];
if($name !='' || $mailid !='' || $address !=''){
$sql = "Insert into user (Name, Age, MailId, Gender, Qualification, Hobbies, Address)
values ('".$_POST["name"]."', '".$_POST["age"]."', '".$_POST["mailid"]."', '".$_POST["gender"]."', '".$_POST["qualification"]."', '".$_POST["hobbies"]."', '".$_POST["address"]."')";
$conn->exec($sql);
echo "Thank you for registering";
} else {
echo "<p>Insertion failed <br/> Please enter the required fields !";
}}
}
catch(PODException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
?>
Try adding the html 5 attribute "required" on all the required input elements. For example
<input type="text" Placeholder="Enter your name" name="name" id="name" required />
You should also check the POST variables in the php code though, as this doesn't really prevent someone from abusing your service. Ex.
if(!isset($_POST['somevar'])) {
// Do insert
}
In html You should use javascript (e.g. jQuery) to control onsubmit event and validate if mandatory fields are filled with proper values, check this link: jQuery.submit()
In php You should check and validate each var before create and execute query. Simple article about it is here: Sanitize and Validate Data with PHP Filters
This would be good for the start I think ;)
Query string should contain placeholders and then statement should be prepared for execution, check this link:
PDOStatement::bindParam

dynamically change html based on user input in a drop down with php

I'm totally new to php and I am trying to dynamically change the form displayed when the user makes a choice on a drop down list. I can get the drop down list to show but it does not display anything when I submit.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Forms</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
If (!isset($_GET['userChoice']))
{ //open the if block to write the html to the screen
?>
<h1>Show your html option form</h1>
<form method="GET" action="thirdtry.php" name="userChoice">
<select size="1" id="choice" name="choice">
<option selected="selected">Choose which form you would like</option>
<option value="feedback">Feedback Form </option>
<option value="help">Help Request Form</option>
</select>
<input type="submit">
</form>
<?php
}//close the if block
else{ //show feedback
if($_GET['userChoice']=="feedback")
{
?>
<h1>Show the feedback form</h1>
<form id="fb" name="fb" method="post" >
<fieldset>
<label>First Name:
<br />
<input type="text" name="fName" id="fName" />
</label>
<br />
<label>Last Name:
<br />
<input type="text" name="lName" id="lName" />
</label>
<br />
<label>Street Address:
<br />
<input type="text" name="address" id="address" />
</label>
<br />
<label>City
<br />
<input type="text" name="city" id="city" />
</label>
<br />
<label>State
<br />
<input type="text" name="state" id="state" />
</label>
<br />
<label>Postcode
<br />
<input type="text" name="postcode" id="postcode" />
</label>
<br />
<label>Country
<br />
<input type="text" name="country" id="country" />
</label>
<br />
<label>Email Address:
<br />
<input type="text" name="FromAddress" id="FromAddress" />
</label>
<br />
<label>Your message:
<br />
<textarea name="message" rows="7" cols="30"></textarea> <br />
</label>
<div>How many stars would you give this site? <br />
(We love 5 stars!)<br />
<input type="radio" name="rating" value="1" />1<br />
<input type="radio" name="rating" value="2" />2<br />
<input type="radio" name="rating" value="3" />3<br />
<input type="radio" name="rating" value="4" />4<br />
<input type="radio" name="rating" value="5" />5<br />
</div>
<br />
<input type="submit" />
<input type="reset" />
</fieldset>
</form>
<?php
}
else
{//must be help form
?>
<h1>Show the help form</h1>
<form id="help" method="post" >
<fieldset>
<label>First Name:
<br />
<input type="text" name="fNameHelp" id="fNameHelp" />
</label>
<br />
<label>Last Name:
<br />
<input type="text" name="lNameHelp" id="lNameHelp" />
</label>
<br />
<label>Street Address:
<br />
<input type="text" name="addressHelp" id="addressHelp" />
</label>
<br />
<label>City
<br />
<input type="text" name="cityHelp" id="cityHelp" />
</label>
<br />
<label>State
<br />
<input type="text" name="stateHelp" id="stateHelp" />
</label>
<br />
<label>Postcode
<br />
<input type="text" name="postcodeHelp" id="postcodeHelp" />
</label>
<br />
<label>Country
<br />
<input type="text" name="countryHelp" id="countryHelp" />
</label>
<br />
<label>Email Address:
<br />
<input type="text" name="FromAddress" />
</label>
<br />
<label>Your message:
<br />
<textarea name="messageHelp" rows="7" cols="30"> </textarea> <br />
</label>
<div>How Would you like to be contacted?<br />
(Choose all that apply) <br />
<input type="checkbox" name="ckemail" id="ckemail" value="email" onclick="return validateHelpForm()"/>email<br />
<input type="checkbox" name="cktelephone" id="cktelephone" value="telephone" onclick="return validateHelpForm()"/>telephone<br />
</div>
<br />
<input type="submit" />
<input type="reset" />
</fieldset>
</form>
<?php
}//close the if block
}
?>
</body>
</html>
You're checking for the wrong variable:
If (!isset($_GET['userChoice']))
should be
If (!isset($_GET['choice']))
Also, why are you capitalizing If? (That won't cause an issue - it's just weird ;)
Well first off, do you want the page to refresh, or would you like it to change dynamically without a refresh, using Javascript. From your brief description, I am thinking you want the change to happen without a refresh.
And being a "novice", I would advise you use Jquery as your Framework as opposed to full blown javascript. Here is what I think you're trying to accomplish.
Since PHP is a server-side programming language, you can't dynamically change a webpage without a refresh. Javascript and Jquery are client-side, so many things can happen in your browser without the need or a refresh.
LINK: Here is the example I just created.
////////jquery/javascript///////
$('#changeme').change(function(){
var value = $('#changeme').val();
if(value == 1){
$('#dis1').show();
$('#dis2').hide();
}
else if(value == 2){
$('#dis1').hide();
$('#dis2').show();
}
else{
$('#dis1').hide();
$('#dis2').hide();
}
});
////////HTML///////
<select id="changeme">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<div style="display:none;" id="dis1">Displaying 1</div>
<div style="display:none;" id="dis2">Displaying 2</div>

My table is not being displayed

I am trying to make a registration page for a website however for some reason it won't display my table? I can't seem to locate the problem and it was working fine earlier. My site can be accessed on the server at cs12jkk.icsnewmedia.net
I am a second year undergraduate at the university of Leeds and i'm trying to make a log in and system as part of a project and can't get it to display anything at all!
<?php require_once("functions.inc");?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="register.js">
<link rel="stylesheet" type="text/css" href="form.css">
<title>Registration Page</title>
</head>
<body>
<form id="userForm" method="POST" action="register-process.php">
<div>
<fieldset>
<legend>Registration Information</legend>
<div id="errorDiv">
<?php
if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) {
unset($_SESSION['formAttempt']);
print "Errors encountered<br />\n";
foreach ($_SESSION['error'] as $error) {
print $error . "<br />\n";
} //end foreach
}
?>
</div>
<label for="fname">First Name:* </label>
<input type="text" id="fname" name="fname" />
<span class="errorFeedback errorSpan"
id="fnameError"> First Name is required</span>
<br />
<label for="lname">Last Name:* </label>
<input type="text" id="lname" name="lname">
<span class="errorFeedback errorSpan"
id="lnameError">Last Name is required</span>
<br />
<label for="email">E-mail Address:*</label>
<input type="text" id="email" name="email">
<span class="errorFeedback errorSpan"
id="emailError">E-mail is required</span>
<br />
<label for="password1">Password:*</label>
<input type="password" id="password1" name="password1"> <span class="errorFeedback errorSpan"
id="password1Error">Password required</span>
<br />
<label for="password2">Verify Password:*</label>
<input type="password" id="password2" name="password2">
<span class="errorFeedback errorSpan"
id="password2Error">Password required</span>
<br />
<label for="addr">Address: </label>
<input type="text" id="addr" name="addr">
<br />
<label for="city">City:</label>
<input type="text" id="city" name="city">
<br />
<label for="state">State:</label>
<select name="county" id="county">
<option></option>
<option value="AL">Alabama</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="FL">Florida</option>
<option value="Il">Illinois</option>
<option value="NJ">New Jersey</option>
<option value="NY">New York</option>
<option value="WI">Wiscon</option>
</select>
<br />
<label for="zip">ZIP:</label>
<input type="text" id="zip" name="zip">
<br />
<label for="phone">Phone Number:</label>
<input type="text" id="phone" name="phone">
<span class="errorFeedback errorSpan"
id="phoneError">Format: xxxx-xxx-xxxx</span>
<br />
<br />
<label for="mobile"> Number Type:</label>
<input class="radioButton" type="radio"
name="phonetype" id="mobile" value="mobile">
<label class="radioButton" for="mobile">Mobile</label>
<input class="radioButton" type="radio"
name="phonetype" id="home" value="home">
<label class="radioButton" for="home">Home</label>
<span class="errorFeedback errorSpan phoneTypeError"
id="phonetypeError">Please choose an option</span>
<br />
<input type="submit" id="submit" name="submit">
</fieldset>
</div>
</form>
</body>
</html>
If you are talking about: http://cs12jkk.icsnewmedia.net/RestaurantApplication/register.php
If you look at the html source you will see the html is all there. The problem is with line 5:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="register.js">
You don't have a closing /> or a </script> after you include register.js so all of the html after that isn't being rendered because it assumes it is part of your <script>.

Cannot store radio button value in table

I am trying to save the value of the radio buttons in my database table choice. I get the message Data saved successfully but no value is stored in the table.
Form:
<form id="myForm" method="post" action="">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<center<legend>Choose in which category you'd like to be included</legend></center>
<p><input type="radio" name="choice[]" value="player" id="player" class="custom" />
<label for="player">Player</label>
<input type="radio" name="choice[]" value="coach" id="coach" class="custom" />
<label for="coach">Coach</label>
<input type="radio" name="choice[]" value="supporter" id="supporter" class="custom" />
<label for="supporter">Supporter</label>
<input type="radio" name="choice[]" value="sponsor" id="sponsor" class="custom" />
<label for="sponsor">Sponsor</label>
<input type="radio" name="choice[]" value="alumni" id="alumni" class="custom" />
<label for="alumni">Alumni</label>
<input type="radio" name="choice[]" value="other" id="o" class="custom" />
<label for="o">Other</label>
</fieldset>
</div>
<div data-role="fieldcontain">
<label for="name">Please enter your name:</label>
<input type="text" name="name" id="name" class="required" value="" autocomplete="off" /><br />
<label for="email">Please enter your e-mail:</label>
<input type="text" name="email" id="email" value="" class="required" autocomplete="off" /><br />
<label for="phone">Please enter your phone number:</label>
<input type="number" name="phone" id="phone" value="" class="required" autocomplete="off" />
<br><br>
<label for="other">Other comments</label>
<textarea name="other" id="other" autocomplete="off" placeholder="Anything else you'd like to add?">
</textarea>
<p><strong id="error"></strong></p>
<br><br>
<input type="submit" id="save" name="save" value="Submit Form" />
<p id="response"></p>
</form>
</body>
</html>
PHP:
<?php
$mysqli = new mysqli('localhost', 'root', '', 'E-mail list');
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if(isset($_POST['save']))
{
$name = $mysqli->real_escape_string($_POST['name']);
$email = $mysqli->real_escape_string($_POST['email']);
$phone = $mysqli->real_escape_string($_POST['phone']);
$other = $mysqli->real_escape_string($_POST['other']);
$choice = $mysqli->real_escape_string($_POST['choice']);
$query = "INSERT INTO Players (`name`,`email`,`phone`,`other`,`choice`) VALUES ('".$name."','".$email."','".$phone."','".$other."','".$choice."')";
if($mysqli->query($query))
{
echo 'Data Saved Successfully.';
}
else
{
echo 'Cannot save data.';
}
}
?>
var_dump($_POST) to sere what data flooding in.
One thing more to check if its save or submit ? in $_POST['save']
EDIT
After getting your full form - the error lies in your center tag
Change <center<legend> TO <center><legend>
The error - ↑ in this tag

Categories