Hi guys,
I have had my fair share of experience with jQuery but have never
dared go near the AJAX uses just because of the effect it has on my
brain and causes me to become obsessive with fixing errors.
So, here I am with an error...
I have my usersystem.js and here is the login section which
deals with the result of the user attempting to login.
- });
- $("#logincontent").on('click',
'#login', function(){
- var
loginusername = $("#loginusername").val();
- var
loginpassword = $("#loginpassword").val();
- var
dataString = 'loginusername='+ loginusername +
'&loginpassword='+ loginpassword;
- if(loginusername==''||loginpassword=='')
- {
- alert("You
left the username or password field blank, oops.");
- }
- else
- {
- $.ajax({
- type: "POST",
- url: "files/php/login.php",
- data: dataString,
- cache: false,
- success: function(result){
-
$("#content").html('<div
class="exclusivetransparentboxleft"></div><div class="exclusivetransparentboxright"></div>');
-
$('.exclusivetransparentboxleft').load('files/php/usercp.php');
-
$("#navigation").html('<div
id="navigationitem">Home</div><div
id="navigationitem">About Us</div><div
id="navigationitem">Support</div><div
id="navigationitem">Add Review</div><div
id="navigationitem">View Venues</div><div
id="navigationitem">Book Venues</div>');
- }
- });
- }
- return false;
- });
Now,
as you can see, regardless of whether the user has entered the correct
username or password it allows them to login with any name or
password, due to the 'success' state running the result
function once the script understands the data has been sent.
So, how would I go about changing the result based on the outcome
of a PHP If statement, like in the login.php file I have below...
- <?php
- session_start();
- include("connect.php");
- $loginusername
= $_POST["loginusername"];
- $loginpassword
= $_POST["loginpassword"];
- $stmt
= $conn->prepare("SELECT * FROM users WHERE username=:theusername");
- $stmt->bind_param(":theusername", $loginusername);
- $row
= $stmt->fetch();
-
if (password_verify($loginpassword, $row['password']))
- {
-
$_SESSION["logged"] = $loginusername;
- }else{
- ?>
- <p
style="font-size: 16px;"><b>Incorrect</b></p>
- <p>We're
sorry to report that the username and password combination you
entered does not exist, if you would like to try to login again
then please click <a href="javascript:loadContent('#logincontent','login.html');">here.</a></b></p>
- <?php
- }
- ?>
As
you can see, if they login, it sets the session to store the username
to keep them logged in, if it's not successful you can see the
error result.
I just don't know how to do what I'm doing in the PHP file
in the JS file, I've been trying for two days straight now and
still nothing.
Any help is extremely appreciated.
Thanks for any suggestions or opinions put forward.