Variable storage and updating fields with AJAX

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

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

#31 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 06:03 PM

I'm trying to use the print_r function but whenever I try to run login.php it brings up index.php.

nvm, I commented out my redirect and I can run the login now. Checking variables.

This post has been edited by Darkranger85: 10 February 2013 - 06:05 PM

Was This Post Helpful? 0
  • +
  • -

#32 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 06:15 PM

Ok, I have some errors. They seem to be undefined variable errors which I'm not understanding.

Here are the errors:

Notice: Undefined index: user in C:\wamp\www\Projects\game\php\login.php on line 11

Notice: Undefined index: pass in C:\wamp\www\Projects\game\php\login.php on line 12

Notice: Undefined variable: pass2 in C:\wamp\www\Projects\game\php\login.php on line 43

Notice: Undefined variable: pass_hash in C:\wamp\www\Projects\game\php\login.php on line 43

And, when I use print_r on $user_id it prints the number 2. That is along with the errors.

I'm thinking that the errors on lines 11 and 12 might be responsible for putting the whole thing out of wack but I don't know why it's giving an error. I checked the form on index.php and the id is correct, the action and method of the form is correct. . .
Was This Post Helpful? 0
  • +
  • -

#33 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 06:55 PM

I've used var_dump on my mysql and on my inputs and everything seems to be fine. When I hit submit on the form all the correct database information is returned.

I'm stumped.
Was This Post Helpful? 0
  • +
  • -

#34 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,571
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 06:55 PM

The form data is not being posted correctly, or their names differ. Add

print_r($_POST); 

to the top of the page to see the entire post array. (View the Source for the page to read this clearly.)

I checked the form on index.php and the id is correct

POST data refers to the name's of the controls, not their id's.

Post your html form-page.

This post has been edited by andrewsw: 10 February 2013 - 06:56 PM

Was This Post Helpful? 0
  • +
  • -

#35 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 06:59 PM

the ids and the names are the same.

Checked the print_r of the $_POST and it all looks fine.

Here is the index.php

<?php
ob_start();
session_start();

$ipa = $_SERVER['REMOTE_ADDR'];

?>

<!DOCTYPE HTML>
<html lang="en">
	<head>
		<title>Earth Past - Fight and Survive</title>
		<link href="styles.css" rel="stylesheet" type="text/css" media="screen" />
	</head>
	<body>
		<section id="container">
			
			<header id="header">
				
			</header>
			
			<nav id="leftcol">
				<ul>
				    Menu
				    <hr />				    
				    <li><a href="register.php">Register</a></li>
				    <li><a href="#">Forums</a></li>
				    <li><a href="stories.php">Stories</a></li>
				    <li><a href="faqs.php">FAQs</a></li>
				    <li><a href="about.php">About Us</a></li>
				    <li><a href="contact.php">Contact</a></li>
				</ul>
			</nav>
			
			<article id="centercol">
				
			</article>
			
			<section id="rightcol">
				<form id="login" action="php/login.php" method="post">
				    <fieldset class="logfieldset">
				        <legend>Log In</legend>			        		        
				        Username:<br />
				        <input id="user" name="user" type="text" maxlength="30" /><br />
                        Password:<br />
                        <input id="pass" name="pass" type="password" maxlength="40" /><br />
                        <input id="submit" name="submit" type="submit" value="Login" />
                        IP: <?php echo $ipa; ?>    
				    </fieldset>				    
				</form>
				
				<form id="play" action="empire.php" method="link">
					<fieldset class="logfieldset">
						<legend>Already Logged In?</legend>
						Enter the game: <input id="playBtn" type="submit" value="Play" />
					</fieldset>
				</form>
			</section>
			
			<footer id="footer">
				<hr />
				<p>Copyright 2013 Mythril Games All Rights Reserved </p>
			</footer>			
			
		</section>		
	</body>	
</html>


Was This Post Helpful? 0
  • +
  • -

#36 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,571
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 07:14 PM

What is method-"link"? Never encountered that..

You are echoing $ipa but it is not in a form element: should it be?

Quote

Checked the print_r of the $_POST and it all looks fine.

You are making it difficult for people to help you :whistling: - what does it show..?!

<ul>
    Menu
      <hr /> 

ULs should only contain LIs (did it mention this to you before or perhaps it was someone else recently..)
Was This Post Helpful? 0
  • +
  • -

#37 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 07:16 PM

method="link" is a way to turn the button into a link. Works like a charm. That button leads into the game if the user has already started a session.

The IP is currently just there for looks. I was playing with it mainly lol.

And I apologize. The output of the print_r is as follows:

Array ( [user] => Darkranger85 [pass] => ***********[submit] => Login )

The stars are my password and it printed it out exactly as I typed it into the login form.

As for the list, it must have been someone else. Is there a reason? It's never given me a problem before.

This post has been edited by Darkranger85: 10 February 2013 - 07:17 PM

Was This Post Helpful? 0
  • +
  • -

#38 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,571
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 07:23 PM

Quote

Is there a reason? It's never given me a problem before.

It means the HTML is malformed. If it is sufficiently malformed then the form-data may not be posted correctly. But this particular aberration :) is not significant enough to be a problem.

print_r() for your sql statements, just before you execute them, and test them in PhpMyAdmin (or equivalent).
Was This Post Helpful? 0
  • +
  • -

#39 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 07:37 PM

By "before you execute them" you mean before the mysqli_query function? So test the $query?
Was This Post Helpful? 0
  • +
  • -

#40 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 10 February 2013 - 07:45 PM

Here are the results of testing each of the mysql arrays and variables just after the query.

$result:

mysqli_result Object ( [current_field] => 0 [field_count] => 4 [lengths] => Array ( [0] => 13 [1] => 32 [2] => 1 [3] => 1 ) [num_rows] => 1 [type] => 0 )

$row:

Array ( [password] => 727ykC8DkpEXA [salt] => 72a6627c8d97db8963d712805043b615 [id] => 1 [account_level] => 4 )

$num_rows:

1

$account_level:

4
Was This Post Helpful? 0
  • +
  • -

#41 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,571
  • Joined: 12-December 12

Re: Variable storage and updating fields with AJAX

Posted 11 February 2013 - 02:57 AM

View PostDarkranger85, on 10 February 2013 - 06:15 PM, said:

Ok, I have some errors. They seem to be undefined variable errors which I'm not understanding.

Here are the errors:
Notice: Undefined index: user in C:\wamp\www\Projects\game\php\login.php on line 11
Notice: Undefined index: pass in C:\wamp\www\Projects\game\php\login.php on line 12

Those line numbers are not for these lines:
$user = trim($_POST['user']);
$pass = trim($_POST['pass']);

but probably for these lines (of your posted code):
$pass_hash;
$account_level;
$log_date;//Defined later

You can't just list variables like this; either assign them values or remove these lines.
Was This Post Helpful? 0
  • +
  • -

#42 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 11 February 2013 - 07:14 AM

Noted and fixed.

Unfortunately the errors still remain. :-(
Was This Post Helpful? 0
  • +
  • -

#43 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 11 February 2013 - 12:41 PM

When I get home I might just rewrite the whole login script line by line and see what happens.
Was This Post Helpful? 0
  • +
  • -

#44 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3393
  • View blog
  • Posts: 9,591
  • Joined: 08-June 10

Re: Variable storage and updating fields with AJAX

Posted 13 February 2013 - 08:24 AM

a bit late though, but two comments to the thread:
- mysqli_select_db() is (for the regular use-case) obsolete. you can pass the DB name to the connector
$link = mysqli_connect($host, $user, $pass, $db_name);
// or
$link = new mysqli($host, $user, $pass, $db_name);
// doesn’t matter which one you use, both $link are the same


- for a Java​Script game, jQuery only plays a role when it comes to the GUI (it is very efficient for accessing the DOM and for AJAX, but the game logic itself is just plain JS)
Was This Post Helpful? 0
  • +
  • -

#45 Darkranger85  Icon User is offline

  • D.I.C Head

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

Re: Variable storage and updating fields with AJAX

Posted 13 February 2013 - 05:29 PM

Ok, thanks for the info!

At the moment my plan is for the main scripts for the game mechanics is to use PHP. I only really plan on using Jquery for the front end visual aspect of the game.

However, I have to figure out how to get my login/registration system working. I'm actually trying to get PDO to work for the database aspects but I'm getting extremely frustrated trying to get it to work.

It's giving me a syntax error:

PDOException: SQLSTATE[HY000]: General error in C:\wamp\www\Projects\Planet Ruin\php\regval.php on line 142

$sql = "INSERT INTO `player_data`
				(`username`, `empire_name`, `ruler_name`, `founding_group`, `government`, `population`, `currency`, `p_currency`, `scrap`, 
				`food`, `fuel`, `salvage_wpn`, `scrap_wpn`, `morale`, `initiative`, `influence`, `farms`, `housing`, `scrap_yards`, `barracks`, 
				`taverns`, `scouts`, `militia`, `infantry`, `heavy_infantry`, `technicals`, `tanks`, `gate`, `tower`, `wall`, `tunnels`, `dogs`)
				VALUES
				(:user, :empire_name, :ruler_name, :founding_group, :government, '25', '1000', '100', '1000', '1000', '0', '0', '5', 
				'10', '100', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0')";
				
		$query = $conn->prepare($sql);
		
		$query->bindValue(':user', $user, PDO::PARAM_STR);
		$query->bindValue(':empire_name', $empire_name, PDO::PARAM_STR);
		$query->bindValue(':ruler_name', $ruler_name, PDO::PARAM_STR);
		$query->bindValue(':founding_group', $founding_group, PDO::PARAM_STR);
		$query->bindValue(':government', $government, PDO::PARAM_STR);
		
		
		try { 
    		$query->execute();
		} catch (Exception $e) {
    		exit($e);
		}


Was This Post Helpful? 0
  • +
  • -

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