inserting data to MySQL using a form and php - php

I am currently trying to get form data to insert to a MySQL database using a form and php. The form is not submitting the data and I am not sure if there is an issue with my code or there is something in my database. I have checked numerous times that all the code matches correctly in the database as well as validating my code with no errors. Is there something simple that i have missed?
<?php
$mysqli = new mysqli("localhost", "root", "", "etrading");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if(isset($_POST['submit'])) {
$key=$_POST['ItemID'];
$name= $_POST['Name'];
$description= $_POST['Description'];
$img_path= $_POST['img_path'];
$quantity= $_POST['Quantity'];
$category= $_POST['Category'];
$location= $_POST['Location'];
$saletype= $_POST['Saletype'];
$price= $_POST['Price'];
$duration= $_POST['Duration'];
$payment= $_POST['Payment'];
$query = "INSERT INTO item (ItemID, Name, Description,img_path, Quantity, Category, Location, Saletype, Price,Duration,Payment) VALUES ('$key','$name','$description','$img_path','$quantity','$category','$location','$saletype','$price','$duration','$payment',)";
if (mysqli_query($mysqli, $query)) {
echo "New record created successfully";
} else {
echo "Error: " . $query . "<br>" . mysqli_error($mysqli);
}
}
/* close connection */
$mysqli->close();
?>
I have also set the ItemID to auto increment in the database
And this is my form code that i am using.
<form id="sellitem" action="sellitem.php" method="POST" >
<fieldset>
<h4>Sell Your Item</h4>
<p><label class="title" for="Name">Name:</label>
<input type="text" placeholder="Enter item name" name="Name" id="Name" title="Please enter item name"
><br />
<label class="title" for="Description">Description:</label>
<textarea name="Description" rows="5" cols="33" placeholder="Please describe your item" id="Description" title="Please describe your item" ></textarea><br />
Select image to upload:
<input type="file" name="img_path" id="img_path" ><br>
<label class="title" for="Quantity">Quantity:</label>
<input type="text" placeholder="Number of items" name="Quantity" id="Quantity" title="Number of items" ><br />
<label class="title" for="Category">Category:</label>
<select name="Category" id="Category">
<option value="clothes">Clothes</option>
<option value="books">Books</option>
<option value="electronics">Electronics</option>
<option value="sport">Sport</option>
</select></p>
<label class="title" for="Location">Location:</label>
<input type="text" placeholder="Item Location" name="Location" id="Location" title="Enter item location" ><br />
<label class="title" for="Saletype">Sale Type:</label>
<select name="Saletype" id="Saletype" >
<option value="Auction">Auction</option>
<option value="BuyNow">Buy Now</option>
</select>
<label class="title" for="Price">Price: $</label>
<input type="text" placeholder="00.00" name="Price" id="Price" title="Please enter your name" ><br />
<label class="title" for="Duration">Duration:</label>
<input type="text" placeholder="End date" name="Duration" id="Duration" title="End Date" ><br />
<label class="title" for="Payment">Payment Type:</label>
<select name="Payment" id="Payment" >
<option value="PayPal">PayPal</option>
<option value="Bank Deposit">Bank Deposit</option>
<option value="Card">Credit Card</option>
</select><br>
<div class="submit"><input type="submit" value="submit" /></div>
<div class="reset"><input type="reset" /></div>
</fieldset>
</form>

Change this line of your code from
<input type="submit" value="submit" />
to
<input type="submit" value="submit" name="submit" />

You are not entering if(isset($_POST['submit'])) {
Add the name attribute to the submit button
<input type="submit" value="submit" name="submit" />

1.Every input field should have name attribute to POST/GET data.
<input type="submit" value="submit" />
to
<input type="submit" value="submit" name="submit" />
2.Due to obscene of name attribute of type="submit" field form posting only
Array
(
[Name] => dsfdsf
[Description] => dfdsf
[img_path] =>
[Quantity] =>
[Category] => clothes
[Location] =>
[Saletype] => Auction
[Price] =>
[Duration] =>
[Payment] => PayPal
)
3.Below query added one extra comma
$query = "INSERT INTO item (ItemID, Name, Description,img_path, Quantity, Category, Location, Saletype, Price,Duration,Payment) VALUES ('$key','$name','$description','$img_path','$quantity','$category','$location','$saletype','$price','$duration','$payment',)";

Related

Can't insert values in database using form

I have a form where users can register other accounts. It was working fine until I changed the data type of the column date to data type date (I was using varchar so I changed it to date). After changing the datatype, the registration stopped working. I don't get an error but I can't see the new account when I try to view the records.
Here's my form:
<div class="main">
<div class="one">
<div class="register">
<center><h3>Add Account</h3></center>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<div>
<label>ID</label>
<input type="text" name="id" required>
</div>
<div>
<label>First Name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label>Last Name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label>Email</label>
<input type="text" name="email" placeholder="user#teamspan.com" required>
</div>
<div>
<label>Username</label>
<input type="text" name="username" required>
</div>
<div>
<label>Password</label>
<input type="password" name="password" required>
</div>
<div>
<label>Street Address</label>
<input type="text" name="street" required>
</div>
<div>
<label>Town/Suburb</label>
<input type="text" name="town" required>
</div>
<div>
<label>City</label>
<input type="text" name="city" required>
</div>
<div>
<label>Contact</label>
<input type="text" name="contact" required>
</div>
<div>
<label>Gender</label>
<select name="gender" required>
<option disabled selected hidden>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div>
<label>User Levels</label>
<select name="user_levels" required>
<option disabled selected hidden>Select Access Level</option>
<option value="0">Employee</option>
<option value="1">Administrator</option>
<option value="2">Manager</option>
<option value="1">HR</option>
</select>
</div>
<div>
<label>Date</label>
<input type="text" readonly="readonly" name="date" value="<?php echo date("m/j/Y");?>" required>
</div>
<div>
<label>Sick Leave</label>
<input type="text" name="sickleave" required>
</div>
<div>
<label>Vacation Leave</label>
<input type="text" name="vacationleave" required>
</div>
<div>
<label>Picture (Link)</label>
<input type="text" name="picture" value="img/emp/" required>
</div>
<div>
<label></label>
<input type="submit" name="submit" value="Add Account" class="button" style="color: white;" />
<a href="hr_panel.php"><input type="button" value="Back" class="button" style="color: white;" />
</div>
</form>
</div>
</div>
And here's code_exec.php
<?php
session_start();
include('connection.php');
$id=$_POST['id'];
$username=$_POST['username'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$street=$_POST['street'];
$town=$_POST['town'];
$city=$_POST['city'];
$contact=$_POST['contact'];
$gender=$_POST['gender'];
$password=$_POST['password'];
$user_levels=$_POST['user_levels'];
$date=$_POST['date'];
$picture=$_POST['picture'];
$sickleave=$_POST['sickleave'];
$vacationleave=$_POST['vacationleave'];
mysqli_query($bd, "INSERT INTO employee(id, firstname, lastname, username, email, street, town, city, contact, gender, password, user_levels, date, picture, sickleave, vacationleave)
VALUES ('$id', '$firstname', '$lastname', '$username', '$email', '$street', '$town', '$city', '$contact', '$gender', '$password', '$user_levels', '$date', '$picture', '$sickleave', '$vacationleave')");
echo "<script>alert('Successfully Added!'); window.location='register.php'</script>";
mysqli_close($con);
?>
Database Schema:
DB Schema
As others have already stated, your date format may not be correct. And you need to look at securing your queries against sql injection.
In order to get you date issue fixed try replacing:
$date=$_POST['date'];
With:
$date=date('Y-m-d', strtotime($_POST['date']));
The Date format for sql is described as YYYY-MM-DD meaning a four digit year-two digit month - two digit day.
You need to convert the received date from your input date :
$dt = \DateTime::createFromFormat('m/j/Y', $_POST['date']);
See this StackOverflow answer for more informations.
Moreover, as #Syscall said, you should also pay attention to your query which is open to SQL injections. To prevent that, you should use a PDO statement, for example :
$stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name');
$stmt->execute(array('name' => $name));
Example taken from How can I prevent SQL injection in PHP?

I got undefined index while upload file

Where is my mistake in php code or html? I want upload file .jpeg or .pdf in my db. All field in form were saved except the ile that i want to upload.
So here is my php code,
<?php
if(isset($_POST['new']))
{
$host="xxx";//host name
$username="xxx"; //database username
$word="";//database word
$db_name="xxx";//database name
$tbl_name="doc"; //table name
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");//connection string
$title =$_REQUEST['title'];
$date = $_REQUEST['date'];
$from_to = $_REQUEST['from_to'];
$details = $_REQUEST['details'];
$d_location = $_REQUEST['d_location'];
$d_stat = $_REQUEST['d_stat'];
$upfile = $_REQUEST['upfile'];
$in_ch=mysqli_query($con,"insert into doc(`title`,`date`,`from_to`,`details`,`d_location`,`d_stat`,`upfile`) values ('$title','$date','$from_to','$details','$d_location','$d_stat','$upfile')");
if($in_ch==1)
{
echo'<script>alert("Inserted Successfully")</script>';
}
else
{
echo'<script>alert("Failed To Insert")</script>';
}
}
?>
and this is my html form
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="new" value="1" />
<p><input type="text" name="title" placeholder="Fail Title" required />
<input type="date" name="date" placeholder="Date" required /></p>
<p><input type="text" name="from_to" placeholder="From/To by" required /></p>
<p> Details: <br><textarea name="details" required></textarea></p>
<p>Location: <select name="d_location">
<option value="Local A">Local A</option>
<option value="local B">Local B</option>
<option value="local C">Local C</option>
</select></p>
<p>Status: <select name="d_stat">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select></p>
<p>Choose file to upload: <input type="file" name ="upfile" required/></p>
<input name="submit" type="submit" value="Create new" />

get addition without button click

Can anyone help me to get the addition of Basic Salary and Allowance I and insert it in Total Day Rate without clicking a button. here's my php code.
Here's a Screen Shot of my UI.
Code :
<?php
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("laboursalary", $connection);
if(isset($_POST['submit'])){
$ID = $_POST['ID'];
$Name = $_POST['Name'];
$Location = $_POST['Location'];
$Category = $_POST['Category'];
$LabourSupplier = $_POST['LabourSupplier'];
$Home = $_POST['Home'];
$Mobile = $_POST['Mobile'];
$BasicSalary = $_POST['BasicSalary'];
$Allowance1 = $_POST['Allowance1'];
$Allowance2 = $_POST['Allowance2'];
$DayRate = $_POST['$DayRate'];
$OTrate = $_POST['OTrate'];
if($ID !=''||$Name !=''){
$query = mysql_query("insert into attendance(ID, Name, Location, Category,LabourSupplier,Home,Mobile,BasicSalary,Allowance1,Allowance2,DayRate,OTrate) values ('$ID','$Name','$Location','$Category','$LabourSupplier','$Home','$Mobile','$BasicSalary','$Allowance1','$Allowance2','$DayRate','$OTrate')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysql_close($connection);
?>
After I enter the values for Basic Salary and Allowance 1, I want to get the addition of those two in Day Rate automatically.
this is my HTML code.
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
</form>
As I understood your question, your HTML code should be like,
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="0" id="bassal" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="0" id="all1" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="0" id="all2" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" id="DayRate" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
</form>
<script >
$(document).ready(function (){
$('#bassal').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
$('#all1').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
$('#all2').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
});
</script>
I've added jQuery, that does your work, and you don't need to do addition on PHP side.
This is how it would be done using a submit for post as these are all _POST values... Though to accomplish this without pressing a button would be JS/Angular/J Query/AJAX...
....
$BasicSalary = $_POST['BasicSalary'];
$Allowance1 = $_POST['Allowance1'];
$Allowance2 = $_POST['Allowance2'];
$DayRate = $_POST['$DayRate'];
$OTrate = $_POST['OTrate'];
//Set a new variable with the addition of the two `Basic Salary` and `Allowance 1`
//for the insertion into your column `dayRate`
$adustedDayRate = $BasicSalary + $Allowance1;
if($ID !=''||$Name !=''){
if($query != false){
$query = mysql_query("INSERT INTO `attendance` (ID, Name, Location, Category,LabourSupplier,Home,Mobile,BasicSalary,Allowance1,Allowance2,DayRate,OTrate) values ('$ID','$Name','$Location','$Category','$LabourSupplier','$Home','$Mobile','$BasicSalary','$Allowance1','$Allowance2','$adustedDayRate','$OTrate')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}esle{ $_SESSION['err'] = "ERROR: ".--- MySQL error handle here --- }
}
else{
echo "Some Fields are Blank....!!</p>";
}
}
mysql_close($connection);
Using Angular, you could place a placeholder element in your form input for `DayRate, then add the call back for the ng-model element for the two inputs you wish to add. Something like this here:
<div ng-app="">
<p>BasicSalary : <input type="number" ng-model="BasicSalary" placeholder="Basic Salary"></p>
<p>AllowanceI : <input type="number" ng-model="AllowanceI" placeholder="Allowance I"></p>
<p>DayRate : <input type="number" ng-model="DayRate" placeholder="{{BasicSalary -- AllowanceI}}"></p>
Your code would look like:
<fieldset> Basic Salary:
<input class="input" type="number" ng-model="BasicSalary" name="BasicSalary" value="" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" ng-model="Allowance1" name="Allowance1" value="" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" placeholder="{{ BasicSalary -- Allowance1 }}" value="" />
</fieldset>
Here is a working fiddle of the angular method, simply add the angular library to your server using composer or hosted links, no additional JS is required with the Angular library elements. You can change the value of DayRate as the two other combining inputs are being input.
https://jsfiddle.net/qkpfb90o/1/
Hope this helps!
You can also try with this.
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="" id="BasicSalary" onkeyup="doSum()"/>
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="" id="Allowance1" onkeyup="doSum()"/>
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" id="DayRate" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
<script>
function doSum() {
var Allowance1 = isNaN(document.getElementById('Allowance1').value) ? document.getElementById('Allowance1').value : 0;
var BasicSalary = isNaN(document.getElementById('BasicSalary').value) ? document.getElementById('BasicSalary').value : 0;
var tot = parseInt(Allowance1) + parseInt(BasicSalary);
document.getElementById('DayRate').value = tot;
}
</script>

update query is not working with my code

I am trying to update the record in my database but after submiting form it does not go back to the page committee.php and records does not get updated. Is there any problem with my query?
<?php
include_once('connection.php');
if(isset($_GET['details_id']))
{
$id=$_GET['details_id'];
if(isset($_POST['submit']))
{
$title = $_POST['title'];
$pageno = $_POST['page'];
$author = $_POST['author'];
//$authorimg = $_POST['image'];
$article_status = $_POST['articlestatus'];
$sketch_status = $_POST['sketchstatus'];
$final_approval_person = $_POST['finalperson'];
$final_approval_date = $_POST['finaldate'];
$status = $_POST['status'];
$query = "update details set title='$title', page_no='$pageno', author='$author', article_status='$article_status', sketch_status='$sketch_status', final_approve_person='$final_approval_person', final_approve_date='$final_approval_date', status='$status', where id=$id";
$res = mysqli_query($DBCONNECT,$query);
if($res)
{
header('location:committee.php');
}
else
{
echo mysql_error();
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body style="margin-left:30%;">
<div class="form-style-2">
<div class="form-style-2-heading">Provide Following Information</div>
<form action="" method="post">
<label for="field1"><span>Title <span class="required">*</span></span><input type="text" class="input-field" name="title" value="" /></label>
<label for="field1"><span>Page No. </span><input type="number" class="input-field" name="page"
min="0" max="100" step="10" value="30"></label>
<label for="field2"><span>Author <span class="required">*</span></span><input type="text" class="input-field" name="author" value="" /></label>
<label for="field1"><span>Author Image <span class="required">*</span></span><input type="file" class="input-field" name="image" value="" /></label>
<label for="field4"><span>Article Status</span><select name="articlestatus" class="select-field">
<option value="notrecieved">Not Recieved</option>
<option value="recieved">Recieved</option>
</select></label>
<label for="field4"><span>Sketch Status</span><select name="sketchstatus" class="select-field">
<option value="notapproved">Not Approved</option>
<option value="approved">Approved</option>
</select></label>
<label for="field2"><span>Final Approval Person <span class="required">*</span></span><input type="text" class="input-field" name="finalperson" value="" /></label>
<label for="field2"><span>Final Approval Date <span class="required">*</span></span><input type="date" class="input-field" name="finaldate" value="" /></label>
<label for="field2"><span>Status <span class="required">*</span></span><input type="text" class="input-field" name="status" value="" /></label>
<!--<label for="field4"><span>Regarding</span><select name="field4" class="select-field">
<option value="General Question">General</option>
<option value="Advertise">Advertisement</option>
<option value="Partnership">Partnership</option>
</select></label>
<label for="field5"><span>Message <span class="required">*</span></span><textarea name="field5" class="textarea-field"></textarea></label>
-->
<label><span> </span><input type="submit" value="submit" name="submit" /></label>
</form>
</div>
</body>
</html>
Your query is wrong. Use this
$query = "update details set title='$title', page_no='$pageno',
author='$author', article_status='$article_status',
sketch_status='$sketch_status', final_approve_person='$final_approval_person',
final_approve_date='$final_approval_date', status='$status' where id=$id";
No need comma here status='$status', where id=$id
Also add single quote for $id in the where clause.

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