Я пытаюсь создать форму регистрации и входа в систему, используя JS, PHP и MQSQL.Моя форма входа в систему работает, но когда я регистрирую информацию, в базе данных появляются только идентификатор, имя пользователя и пароль.
Я не уверенпочему пол, вес, рост и адрес электронной почты не являются?
мой код включает в себя;html-форма
<form role="form" id="signform">
<img src="img/regpic.jpg" alt="reg" id="reg">
<div class="form-group">
<input class="form-control" placeholder="Username" name="susername" id="susername" type="text" autofocus>
</div><br>
<div class="form-group">
<input class="form-control" placeholder="Password" name="spassword" id="spassword" type="password">
</div>
<br>
<div class="form-group">
<input class="form-control" placeholder="Email" name="email" id="semail" type="text">
</div><br>
<div class="form-group">
<input class="form-control" placeholder="Gender" name="gender" id="sgender" type="text">
</div><br>
<div class="form-group">
<input class="form-control" placeholder="Weight (kg)" name="weight" id="sweight" type="text">
</div><br>
<div class="form-group">
<input class="form-control" placeholder="Height (inches)" name="height" id="sheight" type="text">
</div><br>
<button type="button" id="signupbutton" class="btn btn-lg btn-primary btn-block"><span class="glyphicon glyphicon-check"></span> <span id="signtext">Sign Up</span></button>
</form>
php-файл регистрации;
<?php
include('conn.php');
if(isset($_POST['susername'])){
$username=$_POST['susername'];
$password=$_POST['spassword'];
$email=$_POST['semail'];
$gender=$_POST['sgender'];
$weight=$_POST['sweight'];
$height=$_POST['sheight'];
$query=$conn->query("select * from user where username='$username'");
if ($query->num_rows>0){
?>
<span>Username already exist.</span>
<?php
}
elseif (!preg_match("/^[a-zA-Z0-9_]*$/",$username)){
?>
<span style="font-size:11px;">Invalid username. Space & Special Characters not allowed.</span>
<?php
}
elseif (!preg_match("/^[a-zA-Z0-9_]*$/",$password)){
?>
<span style="font-size:11px;">Invalid password. Space & Special Characters not allowed.</span>
<?php
}
else{
$mpassword=md5($password);
$conn->query("insert into user (username, password, email, gender, weight, height) values ('$username', '$mpassword', '$email', '$gender', '$weight', '$height')");
?>
<span>Sign up Successful.</span>
<?php
}
}
?>
php-файл входа в систему
<?php
include('conn.php');
session_start();
if(isset($_POST['username'])){
$username=$_POST['username'];
$gender=$_POST['gender'];
$password=md5($_POST['password']);
$weight=$_POST['weight'];
$height=$_POST['height'];
$email=$_POST['email'];
$query=$conn->query("select * from user where username='$username', password='$password', gender='$gender', email='$email', weight='$weight', height='$height'");
if ($query->num_rows>0){
$row=$query->fetch_array();
$_SESSION['user']=$row['userid'];
}
else{
?>
<span>Login Failed. User not Found.</span>
<?php
}
}
?>
и мой js-файл;
$(document).ready(function() {
//bind enter key to click button
$(document).keypress(function(e) {
if (e.which == 13) {
if ($('#loginform').is(":visible")) {
$("#loginbutton").click();
} else if ($('#signupform').is(":visible")) {
$("#signupbutton").click();
}
}
});
$(document).on('click', '#signupbutton', function() {
if ($('#susername').val() != '' && $('#spassword').val() != '' && $('#semail').val() != '' && $('#sgender').val() != '' && $('#sweight').val() != '' && $('#sheight').val() != '') {
$('#signtext').text('Signing up...');
$('#myalert').slideUp();
var signform = $('#signform').serialize();
$.ajax({
method: 'POST',
url: 'https://cs1.ucc.ie/~lmm12/pjt/signup.php',
data: signform,
success: function(data) {
setTimeout(function() {
$('#myalert').slideDown();
$('#alerttext').html(data);
$('#signtext').text('Sign up');
$('#signform')[0].reset();
}, 4000);
window.location.href = "index.html";
}
});
} else {
alert('Please input both fields to Sign Up');
}
});
$(document).on('click', '#loginbutton', function() {
if ($('#username').val() != '' && $('#password').val() != '') {
$('#logtext').text('Logging in...');
$('#myalert').slideUp();
var logform = $('#loginForm').serialize();
setTimeout(function() {
$.ajax({
method: 'POST',
url: 'https://cs1.ucc.ie/~lmm12/pjt/login.php',
data: logform,
success: function(data) {
if (data == '') {
$('#myalert').slideDown();
$('#alerttext').text('Login Successful. User Verified!');
$('#logtext').text('Login');
$('#loginForm')[0].reset();
setTimeout(function() {
window.location.href = "menu.html";
}, 2000);
} else {
$('#myalert').slideDown();
$('#alerttext').html(data);
$('#logtext').text('Login');
$('#logform')[0].reset();
}
}
});
}, 2000);
} else {
alert('Please input both fields to Login');
}
});
});