php submit form, data is not captured - php

I have got this code from a php lesson it worked on the lesson but not on my side, it basically transfer data from one page to another.
can you spot what issue please with the variable, size?
everything else work
Thanks
<form action= "form_script.php" method="POST">
<p> Name : <input type ="text" name = "name" /></p>
<p> Email : <input type ="text" name = "email" /></p
<p>size:
<select name="size">
<option value "small">small</option>
<option value "medium">medium</option>
<option value "large">large</option>
</select>
</p>
<p>Gender :
<input type = "radio" name ="gender" value ="Male"/> Male
<input type = "radio" name ="gender" value ="Female"/> Female
</p>
<input type ="submit" name = "submit" value="submit Button"/>
</form>
on form_script.php
<?php
$name =$_POST['name'];
$email =$_POST['email'];
$size =$_POST['size'];
$gender =$_POST['gender'];
print "<p>Name: $name </br> Email: $email </br>
Size: $size </br>Gender: $gender </p>";
?>

With every HTML-attribute (e.g. value) you have to use = sign to specify the value:
<p>size:
<select name="size">
<option value="small">small</option>
<option value="medium">medium</option>
<option value="large">large</option>
</select>
</p>

Change the option tags to this :
<option value="small"> small </option>
You forgot the = sign

try to format HTML correctly:
<form action="form_script.php" method="POST">
<p> Name : <input type="text" name="name"/></p>
<p> Email : <input type="text" name="email"/></p
<p>size:
<select name="size">
<option value="small">small</option>
<option value="medium">medium</option>
<option value="large">large</option>
</select>
</p>
<p>Gender :
<input type="radio" name="gender" value="Male"/> Male
<input type="radio" name="gender" value="Female"/> Female
</p>
<input type="submit" name="submit" value="submit Button"/>
</form>

Related

Select Array not being sent via $_POST

Here is a small section of my form. It is set up that a user can add information about one munro, or multiple. Hence the use of arrays for input boxes, check boxes and select option boxes.
<fieldset class="row1">
<H2>Munro Details</H2>
<table id="munroTable" class="form" border="0">
<tbody>
<tr>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td>
<label>Name</label>
<input class = "textbox" type="text" maxlength = "30" required="required" name="name[]">
</td>
<td>
<label>Height (metres)</label>
<input class = "textbox" type="number" maxlength = "5" required="required" name="height[]">
</td>
<td>
<label>Classification</label>
<select name = "classification[]">
<optgroup label="Scottish Hills">
<option value="Munro">Munro</option>
<option value="Corbett">Corbett</option>
<option value="Graham">Graham</option>
<option value="Donald">Donald</option>
</optgroup>
<optgroup label="Non Scottish Hills">
<option value="Furth">Furth</option>
<option value="Hewitt">Hewitt</option>
<option value="Wainwright">Wainwright</option>
<option value="Brikett">Brikett</option>
</optgroup>
<optgroup label="UK wide">
<option value="Marilyn">Marilyn</option>
</optgroup>
</select>
</td>
<td>
<label>Topped?</label>
<input type="checkbox" value = "Yes" name="topped[]" checked="checked">
</td>
</tr>
</tbody>
</table>
<p>
<input class = "myButton" type="button" value="Add Munro" onClick="addRow('munroTable')" />
<input class = "myButton" type="button" value="Remove Munro" onClick="deleteRow('munroTable')" />
</p>
</fieldset>
The issue I'm having is with the select option for "classification".
When I use echo "<br>All data".print_r($_POST); so see what data is being sent sucessfully, the classification doesn't show up.
I'm assuming it is something very simple, but I just can't find it.
Thanks for taking the time to look.

Form Data Not posting to database

Can Anyone see what is wrong with the below code.
When I submit the data using HTML form I get as expected the confirmation to confirm Registered. However, when I check the database its not there!
I have checked the names are the same names of each input is correct and can confirm the database is connected successfully, along with the names of the database columns ect...
Any help would be much appreciated.
<?php
if (isset($_POST['carrierinsert'])) {
$acc = $_POST['acc'];
$sql = "SELECT cariers.acc FROM cariers WHERE cariers.acc ='$acc'";
$result = $db->query($sql);
if($result->num_rows > 0) {
echo "<font color='red'>Carrier Already exits</font>";
$sql = "INSERT INTO cariers ( `reg`, `acc`, `accstatus`, `carramid`, `carrfloor`, `pay`, `comms`)
VALUES ( '".$db->real_escape_string($_POST['reg'])."',
'".$db->real_escape_string($_POST['acc'])."',
'".$db->real_escape_string($_POST['accstatus'])."',
'".$db->real_escape_string($_POST['carramid'])."',
'".$db->real_escape_string($_POST['carrfloor'])."',
'".$db->real_escape_string($_POST['pay'])."',
'".$db->real_escape_string($_POST['comms'])."' )";
$insert = $db->query($sql);
echo "<font color='red'>Carrier Inserted</font>";
}
}
?>
<h1>Add New</h1>
<hr>
<form method="post" action=""> Carrier<br />
<input name="reg" type="text" required="required" value="">
<br /><br />
Number<br />
<input name="acc" type="text" required="required" value="">
<br /><br />
Status<br />
<input name="accstatus" type="text" required="required" value="">
Floor<br />
<select name="carrfloor" id="carrfloor">
<option name="carrfloor" Value="1">1</option>
<option name="carrfloor" Value="2">2</option>
</select>
<br /><br />
Pay<br />
<select name="pay" id="pay">
<option selected="selected" name="pay" Value="0">N/A</option>
<option name="pay" Value="1">1%</option>
<option name="pay" Value="1.25">1.25%</option>
<option name="pay" Value="1.5">1.5%</option>
<option name="pay" Value="1.75">1.75%</option>
<option name="pay" Value="2">2%</option>
<option name="pay" Value="2.25">2.25%</option>
<option name="pay" Value="2.50">2.50%</option>
<option name="pay" Value="3.00">3%</option>
</select>
<br /><br />
Additional Charge<br />
<select name="comms" id="comms">
<option name="comms" selected ="selected" Value="Fees">Yes</option>
<option name="comms" Value="No Fees">No</option>
</select>
<br /><br />
Manager<br />
<select name="carramid" id="carramid">
<option name="carramid" Value="Yes">Yes</option>
<option name="carramid" Value="No">No</option>
</select>
<br /><br />
<br /><br />
<input type="submit" class="btn" name="carrierinsert" value="Save" />
</form>
$sql = "INSERT INTO cariers ( reg, acc, accstatus, carramid, carrfloor, pay, comms)
VALUES ( '".{$db->real_escape_string($_POST['reg'])}."',
'".{$db->real_escape_string($_POST['acc'])}."',
'".{$db->real_escape_string($_POST['accstatus'])}."',
'".{$db->real_escape_string($_POST['carramid'])}."',
'".{$db->real_escape_string($_POST['carrfloor'])}."',
'".{$db->real_escape_string($_POST['pay'])}."',
'".{$db->real_escape_string($_POST['comms'])}."' )";
UPDATE
$a = 15;
echo 'this will not write 15: $a'
.PHP_EOL.
"this will write 15: $a"
.PHP_EOL.
"but i can escape a variable anyways. i dont need to change quotes".$a.' dot (.) is the add method for strings'
;
try this:
$sql = "INSERT INTO cariers ( `reg`, `acc`, `accstatus`, `carramid`, `carrfloor`, `pay`, `comms`)
VALUES ( '".$db->real_escape_string($_POST['reg'])."',
'".$db->real_escape_string($_POST['acc'])."',
'".$db->real_escape_string($_POST['accstatus'])."',
'".$db->real_escape_string($_POST['carramid'])."',
'".$db->real_escape_string($_POST['carrfloor'])."',
'".$db->real_escape_string($_POST['pay'])."',
'".$db->real_escape_string($_POST['comms'])."' )";
EDITTED:
try this code
<?php
if (isset($_POST['carrierinsert'])) {
$acc = $_POST['acc'];
$sql = "SELECT cariers.acc FROM cariers WHERE cariers.acc ='$acc'";
$result = $db->query($sql);
if($result->num_rows > 0) {
echo "<font color='red'>Carrier Already exits</font>";
}else{
$sql = "INSERT INTO cariers ( `reg`, `acc`, `accstatus`, `carramid`, `carrfloor`, `pay`, `comms`) VALUES ( '".$db->real_escape_string($_POST['reg'])."', '".$db->real_escape_string($_POST['acc'])."','".$db->real_escape_string($_POST['accstatus'])."','".$db->real_escape_string($_POST['carramid'])."', '".$db->real_escape_string($_POST['carrfloor'])."','".$db->real_escape_string($_POST['pay'])."','".$db->real_escape_string($_POST['comms'])."' )";
$insert = $db->query($sql);
echo "<font color='red'>Carrier Inserted</font>";
}
}
?>
<h1>Add New</h1>
<hr>
<form method="post" action=""> Carrier<br />
<input name="reg" type="text" required="required" value="">
<br /><br />
Number<br />
<input name="acc" type="text" required="required" value="">
<br /><br />
Status<br />
<input name="accstatus" type="text" required="required" value="">
Floor<br />
<select name="carrfloor" id="carrfloor">
<option value="1">1</option>
<option value="2">2</option>
</select>
<br /><br />
Pay<br />
<select name="pay" id="pay">
<option selected="selected" value="0">N/A</option>
<option value="1">1%</option>
<option value="1.25">1.25%</option>
<option value="1.5">1.5%</option>
<option value="1.75">1.75%</option>
<option value="2">2%</option>
<option value="2.25">2.25%</option>
<option value="2.50">2.50%</option>
<option value="3.00">3%</option>
</select>
<br /><br />
Additional Charge<br />
<select name="comms" id="comms">
<option selected ="selected" value="Fees">Yes</option>
<option value="No Fees">No</option>
</select>
<br /><br />
Manager<br />
<select name="carramid" id="carramid">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br /><br />
<br /><br />
<input type="submit" class="btn" name="carrierinsert" value="Save" />
</form>

How can I make a "*required field" error message appear for a drop down menu in a validating PHP form?

I created a form using PHP. The form needs to be validated and it works for every field but the "rate our site" drop down menu. I'm using the same code from the form from other questions (name, email, etc.) for the "rate our site" drop down menu but the "* required field" message doesn't appear when the user leaves it blank. I need that error message to appear, like the others, when the user leaves it blank. How can I fix this? Here's my code:
<!DOCTYPE HTML>
<html>
<head>
<title>Roy Feedback Form Assignment 7</title>
<style> .error {color: #FF0000;} </style>
</head>
<body>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $commentErr = $likesErr = $howErr = $rateErr = "";
$name = $email = $comment = $likes = $how = $rate = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
}
if (empty($_POST["comment"])) {
$commentErr = "Comments are required";
} else {
$comment = test_input($_POST["comment"]);
}
if (empty($_POST["likes"])) {
$likesErr = "Things you liked is required";
} else {
$likes = test_input($_POST["likes"]);
}
if (empty($_POST["how"])) {
$howErr = "How you got to our site is required";
} else {
$how = test_input($_POST["how"]);
}
if (empty($_POST["rate"])) {
$rateErr = "Rating our site is required";
} else {
$rate = test_input($_POST["rate"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Roy Feedback Form Assignment 7</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
E-mail: <input type="text" name="email">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<span class="error">* <?php echo $commentErr;?></span>
<br><br>
Things you liked:
<input type="radio" name="likes" value="Site design">Site design
<input type="radio" name="likes" value="Links">Links
<input type="radio" name="likes" value="Ease of use">Ease of use
<input type="radio" name="likes" value="Images">Images
<input type="radio" name="likes" value="Source code">Source code
<span class="error">* <?php echo $likesErr;?></span>
<br><br>
How you got to our site:
<input type="radio" name="how" value="Search engine">Search engine
<input type="radio" name="how" value="Links from another site">Links from another site
<input type="radio" name="how" value="Deitel.com website">Deitel.com website
<input type="radio" name="how" value="Reference from a book">Reference from a book
<input type="radio" name="how" value="Other">Other
<span class="error">* <?php echo $howErr;?></span>
<br><br>
Rate our site:
<select name="rate">
<option value="">- Please Select -</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<span class="error">* <?php echo $rateErr;?></span>
</select>
<br/><br/>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $comment;
echo "<br>";
echo $likes;
echo "<br>";
echo $how;
echo "<br>";
echo $rate;
?>
</body>
</html>
Thank you so much for the help everyone! It's greatly appreciated.
The span
<span class="error">* <?php echo $rateErr;?></span>
is inside the select...I bet if you inspected the element it does appear just not visible because it's not in an <option> tag. Try moving it outside.
Your error msg should be outside of the <select> scope :
Rate our site:
<select name="rate">
<option value="">- Please Select -</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<span class="error">* <?php echo $rateErr;?></span>
<br/><br/>
HTML5 allows you to validate a form like in your case
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" on>
Name: <input type="text" name="name" required>
<span class="error">*</span>
<br><br>
E-mail: <input type="email" name="email" required>
<span class="error">*</span>
<br><br>
Comment: <textarea name="comment" rows="5" cols="40" required></textarea>
<span class="error">*</span>
<br><br>
Things you liked:
<input type="radio" name="likes" value="Site design" required>Site design
<input type="radio" name="likes" value="Links" required>Links
<input type="radio" name="likes" value="Ease of use" required>Ease of use
<input type="radio" name="likes" value="Images" required>Images
<input type="radio" name="likes" value="Source code" required>Source code
<span class="error">*</span>
<br><br>
How you got to our site:
<input type="radio" name="how" value="Search engine" required>Search engine
<input type="radio" name="how" value="Links from another site" required>Links from another site
<input type="radio" name="how" value="Deitel.com website" required>Deitel.com website
<input type="radio" name="how" value="Reference from a book" required>Reference from a book
<input type="radio" name="how" value="Other" required>Other
<span class="error">*</span>
<br><br>
Rate our site:
<select name="rate" required>
<option value="">- Please Select -</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<span class="error">*</span>
</select>
<br/><br/>
<input type="submit" name="submit" value="Submit">
</form> This will automatically check on-submit form

Access value of selected option in <select> element with PHP

I am trying to create a simple form that will send data to a PHP script upon submitting the form. I am able to access all of the textbox values, and have successfully implemented variables for each of them. However, when I try to access the value of a combo box on my form, I get this error in the PHP:
Notice: Undefined index: cmbProvince in C:\inetpub\wwwroot\krAssignment4\scripts\index.php on line 15
HTML
<form id="orderForm" action="scripts/index.php" method="post" onsubmit="return validateForm()">
<fieldset id="customerInfo">
<legend>Customer Information</legend>
<label for="txtFirstName">Name:</label><br>
<input type="text" id="txtFirstName" name="txtFirstName"
placeholder="First Name" autofocus="true"
oninput="formatFirstName()">
<input type="text" id="txtLastName" name="txtLastName"
placeholder="Last Name" oninput="formatLastName()"><br><br>
<label for="txtAddress">Address:</label><br>
<input type="text" id="txtAddress" name="txtAddress" placeholder="Address"
oninput="formatAddress()"><br>
<input type="text" id="txtCity" name="txtCity" placeholder="City"
oninput="formatCity()">
<select id="cmbProvince" name="cmbProvince">
<option value="on">ON</option>
<option value="qc">QC</option>
<option value="mb">MB</option>
<option value="sk">SK</option>
<option value="ab">AB</option>
<option value="bc">BC</option>
<option value="nb">NB</option>
<option value="nl">NL</option>
<option value="ns">NS</option>
<option value="nu">NU</option>
<option value="pe">PE</option>
<option value="nt">NT</option>
<option value="yt">YT</option>
</select><br>
<input type="text" id="txtPostalCode" name="txtPostalCode"
placeholder="Postal Code" oninput="displayPostalCode()">
<br><br>
<!-- Button that will display the order form -->
<input type="button" id="btnOrder" value="Order"
onclick="showOrderInformation()">
</fieldset><br>
<fieldset id="orderInfo">
<legend>Order Information</legend>
<label for="cmbProduct">Product:</label><br>
<select id="cmbProduct">
<option> -- Select -- </option>
<option>Blackberries</option>
</select>
 # 
<input type="number" id="txtQuantity" name="txtQuantity" value="1"
step="1" min="1" max="50" oninput="displayTotalTax()"><br><br>
</fieldset>
<br><br>
<!-- Button to submit the form to PHP after validation -->
<input type="submit" id="btnSubmit" value="Submit">
</form>
PHP (lines 10 - 19)
/* Capture the user input from the HTML form */
$strFirstName = $_POST['txtFirstName'];
$strLastName = $_POST['txtLastName'];
$strAddress = $_POST['txtAddress'];
$strCity = $_POST['txtCity'];
$strProvince = $_POST['cmbProvince'];
$strPostalCode = $_POST['txtPostalCode'];
Am I typing something wrong? Or missing something? Everything except the combo box is working.
Let me know if I need to include anything else. Thanks!
EDIT
Here is what happens when I try var_dump($_POST);:
Notice: Undefined index: cmbProvince in C:\inetpub\wwwroot\krAssignment4\scripts\index.php on line 15
Notice: Undefined index: cmbProduct in C:\inetpub\wwwroot\krAssignment4\scripts\index.php on line 18
array(6) { ["txtFirstName"]=> string(7) "Kendall"
["txtLastName"]=> string(4) "Roth"
["txtAddress"]=> string(19) "22 Resolution Drive"
["txtCity"]=> string(8) "Millbank"
["txtPostalCode"]=> string(7) "K2K 2K2"
["txtQuantity"]=> string(1) "2" }
Your code works for me with a little bit changes, try this:
<form id="orderForm" action="scripts/index.php" method="post" onsubmit="return validateForm()">
<fieldset id="customerInfo">
<legend>Customer Information</legend>
<label for="txtFirstName">Name:</label><br>
<input type="text" id="txtFirstName" name="txtFirstName"
placeholder="First Name" autofocus="true"
oninput="formatFirstName()">
<input type="text" id="txtLastName" name="txtLastName"
placeholder="Last Name" oninput="formatLastName()"><br><br>
<label for="txtAddress">Address:</label><br>
<input type="text" id="txtAddress" name="txtAddress" placeholder="Address"
oninput="formatAddress()"><br>
<input type="text" id="txtCity" name="txtCity" placeholder="City"
oninput="formatCity()">
<select id="cmbProvince" name="cmbProvince">
<option value="on">ON</option>
<option value="qc">QC</option>
<option value="mb">MB</option>
<option value="sk">SK</option>
<option value="ab">AB</option>
<option value="bc">BC</option>
<option value="nb">NB</option>
<option value="nl">NL</option>
<option value="ns">NS</option>
<option value="nu">NU</option>
<option value="pe">PE</option>
<option value="nt">NT</option>
<option value="yt">YT</option>
</select><br>
<input type="text" id="txtPostalCode" name="txtPostalCode"
placeholder="Postal Code" oninput="displayPostalCode()">
<br><br>
<!-- Button that will display the order form -->
<input type="button" id="btnOrder" value="Order"
onclick="showOrderInformation()">
</fieldset><br>
<fieldset id="orderInfo">
<legend>Order Information</legend>
<label for="cmbProduct">Product:</label><br>
<select id="cmbProduct" name="cmbProduct"> //changes is in this code
<option> -- Select -- </option>
<option value="Blackberries">Blackberries</option>
</select>
 # 
<input type="number" id="txtQuantity" name="txtQuantity" value="1"
step="1" min="1" max="50" oninput="displayTotalTax()"><br><br>
</fieldset>
<br><br>
<!-- Button to submit the form to PHP after validation -->
<input type="submit" id="btnSubmit" value="Submit">
</form>
In your index.php write:
<?php
if(isset($_POST) && !empty($_POST)){
echo "<pre/>";print_r($_POST);die;
}
?>
Output:-
Array
(
[txtFirstName] => a
[txtLastName] => b
[txtAddress] => c
[txtCity] => d
[cmbProvince] => qc
[txtPostalCode] => e
[cmbProduct] => Blackberries
[txtQuantity] => 1
)
Kendall, you were:
missing name for your <select id="cmbProduct">, and
missing value for your cmbProduct options as well
Putting in 'disabled selected' is a good practice as well as people won't be able to select the 'select' option :)
Your code
<select id="cmbProduct">
<option> -- Select -- </option>
<option>Blackberries</option>
</select>
Correct code
<select id="cmbProduct" name="cmbProduct>
<option value="select" disabled selected> -- Select -- </option>
<option value="blackberries">Blackberries</option>
</select>

PHP form submit to sql database

I'm currently creating a custom 'survey'-like form but since I'm new to php, I am not entirely sure how to submit the entries to a database (and make a fieldset required).
I currently have 3 fieldsets, lets call them who, when and what. Who is a simple select field so no problem. When however is a group of radios but two of those have text fields associated that need to be filled if the radio was selected. What is just a textarea.
I understand this much:
Form action is a php file (which contains database connection and
submission)
Form method is post
With the database, how do I submit this data? Especially the second fieldset.
Current Form:
<form action="heroes.php" method="post">
<fieldset>
<h2 class="req">Which Hero?</h2>
<span class="help">We need to know what hero says what line.</span>
<label><span class="title">Hero: </span>
<select>
<?php include 'files/hero-select.php'; ?>
</select>
</label>
</fieldset>
<fieldset id="when">
<h2 class="req">When?</h2>
<span class="help">When is it said? Who is it said to?</span>
<label>To Boss: <input name="when" type="radio" value="boss" /> <input type="text" placeholder="Boss Name" id="bname" size="10" /></label>
<label>To Hero: <input name="when" type="radio" value="hero" /> <input type="text" placeholder="Hero Name" id="hname" size="10" /></label>
<label>Low Health: <input name="when" type="radio" value="lowhp" /></label>
<label>Defeat: <input name="when" type="radio" value="defeat" /></label>
<label>Boss Defeat: <input name="when" type="radio" value="bossd" /></label>
<label>Mob Defeat: <input name="when" type="radio" value="mob" /></label>
<label>Emote: <input name="when" type="radio" value="emote" /></label>
<label>Item Pickup: <input name="when" type="radio" value="item" /></label>
</fieldset>
<fieldset>
<h2 class="req">Quote</h2>
<span class="help">What was said.</span>
<textarea id="quote"></textarea>
</fieldset>
<fieldset>
<input type="submit" value="Submit" /><input type="reset" value="Clear" />
</fieldset>
</form>
hero-select.php:
Black Panther
<option value="Black Widow">
Black Widow
</option>
<option value="Cable">
Cable
</option>
<option value="Captain America">
Captain America
</option>
<option value="Colossus">
Colossus
</option>
<option value="Cyclops">
Cyclops
</option>
<option value="Daredevil">
Daredevil
</option>
<option value="Deadpool">
Deadpool
</option>
<option value="Emma Frost">
Emma Frost
</option>
<option value="Gambit">
Gambit
</option>
<option value="Ghost Rider">
Ghost Rider
</option>
<option value="Hawkeye">
Hawkeye
</option>
<option value="Hulk">
Hulk
</option>
<option value="Human Torch">
Human Torch
</option>
<option value="Iron Man">
Iron Man
</option>
<option value="Jean Grey">
Jean Grey
</option>
<option value="Loki">
Loki
</option>
<option value="Luke Cage">
Luke Cage
</option>
<option value="Moon Knight">
Moon Knight
</option>
<option value="Ms Marvel">
Ms Marvel
</option>
<option value="Nightcrawler">
Nightcrawler
</option>
<option value="Punisher">
Punisher
</option>
<option value="Rocket Raccoon">
Rocket Raccoon
</option>
<option value="Scarlet Witch">
Scarlet Witch
</option>
<option value="Spider-Man">
Spider-Man
</option>
<option value="Squirrel Girl">
Squirrel Girl
</option>
<option value="Storm">
Storm
</option>
<option value="Thing">
Thing
</option>
<option value="Thor">
Thor
</option>
<option value="Wolverine">
Wolverine
</option>
I'm gonna do a short example, with different code (but it works the same).
<form method="POST" action="add.php">
Name: <input type="text" name="name">
Phone: <input type="text" name="phone">
</form>
method="POST" means that it Posts all the info to the action, the action is set to add.php so it posts all the info to add.php.
As you can see every input above has a different name="", what the name property does is:
It sends every value together with a name, this means that the phone input gets send as Phone = "123456" and the name value Name = "2324234".
The add.php code
<?php
if ($_SERVER['REQUEST_METHOD']) == 'POST') {
$name = $_POST['name'];
$phone = $_POST['phone'];
$sql = 'INSERT INTO user '.
'(name,phone) '.
'VALUES ( "$name", "$phone"NOW())';
mysql_select_db('test_db');
$retval = mysql_query( $sql, $conn );
}
First it check if the request is a post, if it is it turns the value's it get send into variables and then it inserts the values into the database.
You can use jQuery with the .post method:
https://api.jquery.com/jQuery.post/
$.post("submittodatabase.php", $( "#yourformid" ).serialize() );

Categories