Variable storage and updating fields with AJAX

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

48 Replies - 3019 Views - Last Post: 14 February 2013 - 07:38 AM

#16 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9389
  • View blog
  • Posts: 35,262
  • Joined: 12-June 08

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 03:59 PM

Awesome!
Was This Post Helpful? 0
  • +
  • -

#17 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:08 PM

:)/> Awesome indeed!

And I figured out that the null value was because my database wasn't being given the values properly, probably for the same reason.

Now the database gets the data properly but as soon as the happened I was suddenly unable to login to the games main page when it worked perfectly before.

And it makes no sense cause I only changed the player database where as my login system only queries the user database. . . .

unless. . . hang on, I have an idea.

This post has been edited by Darkranger85: 10 February 2013 - 04:11 PM

Was This Post Helpful? 0
  • +
  • -

#18 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:12 PM

View PostDarkranger85, on 10 February 2013 - 03:53 PM, said:

Ok, figured that one out. Had to change the functions in my connection script to mysqli as well.

resource.inc.php echoes out:

null

Did you add the correct path? I assume you did.. but (just for completeness) if testing locally it'll be something like 'http://localhost/yourapp/'.

Add was the 'user_id' already/still in the session-data?

Otherwise, if it returns null then it looks like you located the page and the error is in this PHP page. Can you re-post the pages' code as it is now.

This post has been edited by andrewsw: 10 February 2013 - 04:13 PM

Was This Post Helpful? 0
  • +
  • -

#19 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:15 PM

Nope, idea didn't pan out.

Checked my login.php script for mysql functions that had the be changed to mysqli ones and in the end I'm left with the same problem. Not logging in.
Was This Post Helpful? 0
  • +
  • -

#20 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:31 PM

Add

error_reporting(E_ALL);
ini_set('display_errors', '1');


to the top of your PHP script so that you can see all errors.

Use print_r() or var_dump() to view the values of your variables at various points. View the Source of the resultant page and it is easier to read the values that are output.
Was This Post Helpful? 0
  • +
  • -

#21 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:37 PM

Ok, so far I tried the error_reporting.

When I run login.php is says:

Parse error: syntax error, unexpected 'require'

And it refers to my connection script.
Was This Post Helpful? 0
  • +
  • -

#22 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:44 PM

Show some code :)

My guess would be that you have already used require_once() and you are making a second call of require().

This post has been edited by andrewsw: 10 February 2013 - 04:48 PM

Was This Post Helpful? 0
  • +
  • -

#23 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:48 PM

Ok, I'm not getting the unexpected require error now. Missing semi colon on the error reporting. It now gives me no errors at all.

login.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

//Includes//
require 'connection.inc.php';
require 'core.inc.php';
//End Includes//

//Base Variable Initilization//
$user = trim($_POST['user']);
$pass = trim($_POST['pass']);
$pass_hash;
$account_level;
$log_date;//Defined later
$errors = array();
//End Variable Initilization//

if(empty($user) || empty($pass)) {	
	 $errors[] = "You must supply a username and password.";
}

//Run database query and match input to stored data//
	$query = "SELECT `password`, `salt`, `id`, `account_level` 
			  FROM `user_data`
			  WHERE `username`='$user'";

	$result = mysqli_query($conn, $query);
	$row = mysqli_fetch_assoc($result);
	$num_rows = mysqli_num_rows($result);
	$account_level = $row['account_level'];

	if ($num_rows === 1){ //if username is found return that row
		$pass2 = $row['password'];
		$salt = $row['salt'];
		$pass_hash = crypt($pass, $salt);

	} else {
		$errors[] = "Username or Password is invalid.";
	}
	
	//Check if passwords match, check account level, log in if all is valid.
	if ($pass_hash === $pass2){ //if passwords dont match trigger error			
			if ($account_level === 0){
				$errors[] = "Your account is not activated.";
				
				if ($account_level === 5){
					$errors[] = "This account appears to be under ban. If you are recieving this message in error please use the contact page to 
					report the error.";
				}
			}else{
				$log_date = date('Y/m/d', time());
				$query2 = "INSERT INTO `user_data`
			  			  (last_logged)
			  			  `VALUES`
			  			  ('$log_date')";

				mysqli_query($conn, $query2);

				$user_id = mysql_result($result, 0, 'id');
				$_SESSION['user_id'] = $user_id;							
				
				header("Location: ../empire.php");
			}
	} else {
			$errors[] = "Username or Password is invalid.";
	}
?>



connection.inc.php

<?php 
 // Connects to Our Database 
 $db_host = "localhost";
 $db_user = "root";
 $db_pass = "";
 $database = "game_db";
 
 $conn = mysqli_connect($db_host, $db_user, $db_pass);
 
 if (!mysqli_connect($db_host, $db_user, $db_pass) || !mysqli_select_db($conn, $database)){
 	die();
 }
 


Was This Post Helpful? 0
  • +
  • -

#24 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 04:57 PM

Don't put back-ticks around keywords: `VALUES`

(last_logged)
So this is the name of the field? Looks odd with the brackets but should still work.

This post has been edited by andrewsw: 10 February 2013 - 05:07 PM

Was This Post Helpful? 0
  • +
  • -

#25 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 05:05 PM

It is a poor practice to use die(); but, at least while testing, you could at least tack on the error message:

or die('Could not connect: ' . mysqli_error());


and, BTW, although PHP does perform short-circuit evaluation, I would split this:

if (!mysqli_connect($db_host, $db_user, $db_pass) || !mysqli_select_db($conn, $database)){

into two separate statements; it is easier to debug and to read.
Was This Post Helpful? 0
  • +
  • -

#26 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 05:07 PM

I got my syntax for this from reading someone elses tutorial. It's seemed to work for me ok so far but if there is anything wrong with it I can change it.

I got rid of the backticks around the keyword, I thought I had gotten them all, but it's still not working. I'm pouring over my code and I'll use the functions you told me too.

If I find anything I'll let you know. Any ideas let me know lol.
Was This Post Helpful? 0
  • +
  • -

#27 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 05:34 PM

I'm wondering if it's on line 62, the mysql_request.

I tried changing it to mysqli_request but it turns blue and doesn't work.
Was This Post Helpful? 0
  • +
  • -

#28 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 05:40 PM

It should definitely be mysqli_ - you cannot mix these libraries!! But a quick Google confirms there is no such thing as mysqli_request.
Was This Post Helpful? 0
  • +
  • -

#29 Darkranger85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 147
  • Joined: 31-August 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 05:47 PM

Ok, I replaced it with:

$user_id = $row[0];



And it doesn't break it any worse, but it also doesn't solve the problem.
Was This Post Helpful? 0
  • +
  • -

#30 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,442
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 05:53 PM

Do you have an error message, and line number to tell us? Otherwise, use print_r() that I mentioned earlier, particularly with your SQL statements.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4