Answer the question
In order to leave comments, you need to log in
Not added to the database?
In general, the problem is this, the entered data in the input via ajax is sent to the query.php file and there this data is sent to the database, but there is one problem, if you enter only numbers in the login and password, then the entry in the database will be added, and if you enter letters, the entry is not added. How to fix ?
$(document).ready(function(){
$('button').click(function(){
$('.box_error').hide();
var login = [];
var password = [];
login = $('#login').val();
password = $('#password').val();
$.ajax({
method: "POST",
url: "../pages/query.php",
data: { login:login, password:password },
beforeSend: function() {
$('button').html('Загрузка...');
},
success: function( msg ) {
if(msg == 'Errors') {
$('.box_error').show();
$('button').html( 'Войти' );
} else {
$('button').html( msg );
}
}
})
});
});
<?php
include 'config.php';
$login = $_POST['login'];
$password = $_POST['password'];
$query = 'INSERT INTO `users`(`email`, `password`) VALUES ('.$login.', '.$password.')';
mysqli_query($link, $query);
exit("Finish 1");
<?php
$link = mysqli_connect("localhost", "root", "", "test");
Answer the question
In order to leave comments, you need to log in
What's in the logs? What's in the console? Press F12 and see the server response.
And don't use constructs like url: "../pages/query.php",
Always specify an absolute address.
And what are the types of these fields in your database, Int? If it is, then it's clear, change to varchar
$query = 'INSERT INTO `users`(`email`, `password`) VALUES ('.$login.', '.$password.')';
<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);
$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;
/* execute prepared statement */
mysqi_stmt_execute($stmt);
printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));
/* close statement and connection */
mysqli_stmt_close($stmt);
/* Clean up table CountryLanguage */
mysqli_query($link, "DELETE FROM CountryLanguage WHERE Language='Bavarian'");
printf("%d Row deleted.\n", mysqli_affected_rows($link));
/* close connection */
mysqli_close($link);
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question