// Connect to server and select database.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
/* escape entered values to prevent sql nastyness */
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
if(!empty($username) && !empty($password)){
/* we query through our database to search for a username that has been entered */
$query = mysql_query("SELECT * FROM $tbl_name WHERE UserLogin = '$username' AND UserPass='$password'");
if(mysql_num_rows($query) == 1){
/* if there is a match with the database, we select the username and password from the database corresponding to the entered username */
while($row = mysql_fetch_assoc($query)){
$db_username = $row['username'];
$db_password = $row['password'];
}
/* we compare the entered username and password with the ones we just selected from the database */
if($username == $db_username && $password == $db_password){
/* If the entered username and password are correct, return 1 */
echo '1';
}
} else {
/* If the entered username or password do not match, return 2 */
echo 'Username or Password are wrong';
}
} else {
/* If both fields are empty, return 3 */
echo 'Username and Password are empty';
}
< /code>
JavaScript < /p>
$(document).ready(function() {
$('#login_form').submit(function() {
$.ajax({
type: "POST",
url: 'php/check_login_online.php',
data: {
username: $("#username").val(),
password: $("#password").val()
},
success: function(data)
{
if (data === '1') {
window.location.replace('php/search.php');
}
else {
alert(data);
}
}
});
});
});
< /code>
html < /p>
test Login
Ich habe den zusätzlichen Code abgesenkt, aber wenn ich die Anmeldetaste drücke, ändert sich die URL, bleibt jedoch mit dem Benutzernamen und dem Passwort auf der Anmeldeseite, aber es gibt keine Validierung.
/* we query through our database to search for a username that has been entered */ $query = mysql_query("SELECT * FROM $tbl_name WHERE UserLogin = '$username' AND UserPass='$password'");
if(mysql_num_rows($query) == 1){ /* if there is a match with the database, we select the username and password from the database corresponding to the entered username */ while($row = mysql_fetch_assoc($query)){ $db_username = $row['username']; $db_password = $row['password']; } /* we compare the entered username and password with the ones we just selected from the database */ if($username == $db_username && $password == $db_password){ /* If the entered username and password are correct, return 1 */ echo '1'; } } else { /* If the entered username or password do not match, return 2 */ echo 'Username or Password are wrong'; } } else { /* If both fields are empty, return 3 */ echo 'Username and Password are empty'; } < /code> JavaScript < /p> $(document).ready(function() {
[/code] Ich habe den zusätzlichen Code abgesenkt, aber wenn ich die Anmeldetaste drücke, ändert sich die URL, bleibt jedoch mit dem Benutzernamen und dem Passwort auf der Anmeldeseite, aber es gibt keine Validierung.
Ich arbeite an einer Flask -Anwendung, die Blaupausen für die modulare Routenorganisation verwendet. Ich habe eine Hauptplantage, die der Indexseite dient, und einen Auth -Blaupause für...
Ich arbeite an einer Flask -Anwendung, die Blaupausen für die modulare Routenorganisation verwendet. Ich habe eine Hauptplantage, die der Indexseite dient, und einen Auth -Blaupause für...
Ich versuche, eine Login -Seite in PHP Luminova zu erstellen, funktioniert aber nicht gut mit AJAX -Anforderungen. Umleitete die Fehlermeldung nicht auf erfolgreiches Anmeldung oder aktualisiert die...
Ich versuche, eine Login -Seite in PHP Luminova zu erstellen, funktioniert aber nicht gut mit AJAX -Anforderungen. Umleitete die Fehlermeldung nicht auf erfolgreiches Anmeldung oder aktualisiert die...
Ich habe einen Code für WooCommerce -Produktlisten mit AJAX -Load mehr durch Scroll- und Ajax -Filter nach Kategorie erstellt - alles funktioniert großartig, aber es gibt einen Fall, wenn dies nicht...