I'm trying to create a simple login system that will have the forms and everything on one domain (Let's call it Domain A) and the PHP files on another domain (Domain B). Why? Simply because Domain A is more reliable but doesn't support PHP. I'm quite new to all this AJAX stuff, so I'm currently using the resources I've found online.
The Jquery and Forms part of it on Domain A are as below:
<form id="submit" method="post">
<fieldset>
<legend>Enter Information</legend>
<label for="fname">Name:</label>
<input class="text" id="fname" name="fname" size="20" type="text" />
<label for="lname">Email:</label>
<input class="text" id="lname" name="lname" size="20" type="text" />
<button class="button positive"> Submit </button> </fieldset>
</form>
<script>
$(document).ready(function(){
$("form#submit").submit(function() {
// we want to store the values from the form input box, then send via ajax below
var fname = $('#fname').attr('value');
var lname = $('#lname').attr('value');
$.ajax({
type: "POST",
url: "http://domainB.com/somefolder/ajax.php",
data: "fname="+ fname +"& lname="+ lname,
success: function(){
$('form#submit').hide(function(){$('div.success').fadeIn();});
}
});
return false;
});
});
</script>
Please note that the 'lname' and 'fname' are going to represent Name and Email instead of Firstname and Lastname respectively.
The PHP code on Domain B :
<?php
// CLIENT INFORMATION
$uname = htmlspecialchars(trim($_POST['fname']));
$umail = htmlspecialchars(trim($_POST['lname']));
$uip = 12345;
$usecret = "secret";
//Mysql
$con = mysql_connect("mysql.domainB.com","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Connect
mysql_select_db("login_db", $con);
//Insert user details irrespective of whether the user is a member or not to make a log kind of thing
mysql_query("INSERT INTO log_data (Name, Email, IP_ADDRESS, Secret)
VALUES ('$uname', '$umail', '$uip', '$usecret')");
//Now check if the user is a subscriber or not
// mysql_query("SELECT Email, Secret FROM login_data WHERE Email='$umail' AND Secret="secret"");
//I don't know the code to check if the user has logged in correctly
//This is where I need you to help me
//I need to check if the user has logged in correctly, if yes, then return a message saying //success which should be caught by Jquery and displayed as an Alert, or something
//If the user login failed, this php code should return a failure message which again should be caught by Jquery on Domain A and displayed as an alert in the least.
mysql_close($con);
//end Mysql
?>
Things to note here - There are two tables inside the login_db database - log_data which stores the log information and the login_data which stores usernames and passwords. The variable $secret stores the user's password.
The log_data insertion works like a charm, but its the login_data that is bugging me. Any help would be much appreciated. Thanks!
Imag