Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I've got the following code to work now, but there are still a few problems:
- $("#action_button").click(function() {
- $('#success').append("Hello");
- var username = $("#username").val();
- var password = $("#password").val();
- var dataString = '&username=' + username + '&password=' + password;
- if(username=='' || password=='') {
- $('#success').fadeOut(200).hide();
- $('#error').fadeOut(200).show();
- } else {
- $.ajax({
- type: "POST",
- url: "processing/logsig.php",
- data: dataString,
- json: {session_state: true},
- success: function(data){
- if(data.session_state == true) {
- $('#success').append("True");
- } else if(data.session_state == fale) {
- $('#success').append("False");
- }
- }
- });
- }
- });
- It'll process the Php script, but it won't process the JSON... I've got $('#success').append("Hello"); working, but I can't seem to get the ajax json data return to work... It processes the php script because when I reload the page after clicking the action_button, it loads the page that is supposed to come after the user logs in. Any ideas? Also, below is the revised php script:
- <?php
- header('Content-type:application/json');
- session_start();
- include("global-settings.php");
- mysql_connect($dbhost, $dbuser, $dbpass)or die("Could Not Connect: " . mysql_error());
- mysql_select_db($dbname) or die(mysql_error());
- $email = mysql_real_escape_string(strip_tags($_POST["username"]));
- $password = sha1($_POST["password"]);
- $sql = "SELECT * FROM users WHERE username = '{$email}' AND password = '{$password}'";
- $result = mysql_query($sql); // or exit("ERROR: " . mysql_error() . "<br>IN QUERY: " . $sql);
- if (mysql_num_rows($result) > 0) {
- $row = mysql_fetch_array($result);
- $_SESSION["userid"] = $row['user_pid'];
- $json = json_encode(array('session_state' => true));
- echo $json;
- } else {
- $userid_generator = uniqid(rand(), false);
- mysql_query("INSERT INTO users (user_pid, email, password, datetime_registered, is_leader) VALUES ('$userid_generator', '{$email}', '{$password}', NOW(), 'no')");
- $id = mysql_insert_id();
- $leaders = mysql_query("SELECT * FROM users WHERE is_leader LIKE '%yes%'");
- while($rows = mysql_fetch_array($leaders)) {
- if ($rows['is_leader'] == 'yes') {
- $leader_id = $rows['user_pid'];
- mysql_query("INSERT IGNORE INTO friends (node1id, node2id, friends_since, friend_type)
- VALUES('$leader_id', '$userid_generator', NOW(), 'full')");
- }
- $_SESSION["userid"] = $userid_generator;
- }
- if(is_dir($userid_generator)) {
- echo "Something wen't wrong. A bug report has been sent and we are doing what we can to fix it.";
- $message = 'Registration problem on account number $userid_generator. The user succesfully registered, but there is already
- a directory with the account id of $userid_generator.';
- mail($bug_report_email, "Registration Bug!", $message);
- } else {
- mkdir('media/User-PID{' . $userid_generator . '}', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/photos', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/backups', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/videos', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/documents', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/developer', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/developer/apps', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/developer/themes', 0777);
- mkdir('media/User-PID{' . $userid_generator . '}/xml', 0777);
- }
- $json = json_encode(array('session_state' => false));
- echo $json;
- }
- ?>
Add Comment
Please, Sign In to add comment