SamS SamS - 1 year ago 51
MySQL Question

Jquery form submit empty values to Mysql

My IntelXDK HTML5 mobile app form submitting empty values to the MySQL database.

My HTML (Single file app)

<label class="item item-input widget uib_w_6 d-margins" data-uib="ionic/input" data-ver="0" id="fullname">
<input type="text" placeholder="Fullname" name="fullname">
<label class="item item-input widget uib_w_7 d-margins" data-uib="ionic/input" data-ver="0" id="email">
<input type="email" placeholder="Email" name="email">
<label class="item item-input widget uib_w_8 d-margins" data-uib="ionic/input" data-ver="0" id="pass">
<input type="password" placeholder="Password" name="pass">
<button class="button widget uib_w_9 d-margins button-positive" data-uib="ionic/button" data-ver="0" id="signup">
Create Account
<span class="uib_shim"></span>


$(document).on("click", "#signup", function (evt) {
/* your code goes here */
//these two lines take the values from inputs using jquery
var input1 = $("#fullname").val();
var input2 = $("#email").val();
var input3 = $("#pass").val();

//jquery ajax to send values to php using POST
type: 'POST',
url: 'http://localhost/signup.php',
data: {
fullname: input1,
email: input2,
pass: input3
success: function (response) {
//from php using echo

return false;

And the PHP file

// Create connection
$conn = new mysqli("localhost", "user", "pass", "dbname");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

$fullname = Trim(stripslashes($_POST['fullname']));
$email = Trim(stripslashes($_POST['email']));
$pass = Trim(stripslashes($_POST['pass']));

$sql = "INSERT INTO login (fullname, email, pass) VALUES ('$fullname','$email', '$pass')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;


Upon submitting this form, it is creating empty records in MySQL.

Any help appreciated.

Answer Source

This is happening because

<input type="text" placeholder="Fullname" name="fullname">

there is no id like id="fullname" available and you are referring to it.