48 Replies - 1258 Views - Last Post: 14 February 2013 - 07:38 AM
#16
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 03:59 PM
#17
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:08 PM
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
#18
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:12 PM
Darkranger85, on 10 February 2013 - 03:53 PM, said:
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
#19
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:15 PM
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.
#20
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:31 PM
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.
#21
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:37 PM
When I run login.php is says:
Parse error: syntax error, unexpected 'require'
And it refers to my connection script.
#22
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:44 PM
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
#23
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:48 PM
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();
}
#24
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 04:57 PM
(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
#25
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 05:05 PM
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.
#26
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 05:07 PM
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.
#27
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 05:34 PM
I tried changing it to mysqli_request but it turns blue and doesn't work.
#28
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 05:40 PM
#29
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 05:47 PM
$user_id = $row[0];
And it doesn't break it any worse, but it also doesn't solve the problem.
#30
Re: Variable storage and updating fields with AJAX
Posted 10 February 2013 - 05:53 PM
|
|

New Topic/Question
Reply






MultiQuote



|