PHP Question

C++, C#, Java, PHP, ect...
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: PHP Question

Post by hallsofvallhalla »

ah you are missing your where.....insert into players.......where id=$id ect
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: PHP Question

Post by Torniquet »

SpiritWebb wrote:
Torniquet wrote:im pretty sure you need to have the include in there lol. as its trying to access a DB. in halls tut as far as i can remember he is not accessing any DBs.

stick the include in and see if it works :p
i did place the include_once, its in the above code, and it still doesnt work.
feel free to call me spasticated.... but i cannot see it lol
New Site Coming Soon! Stay tuned :D
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

hallsofvallhalla wrote:ah you are missing your where.....insert into players.......where id=$id ect
Ok, so it should look like: (Im at work, so wont be able to test this until tonight, but to make sure I get this right)

Code: Select all

<?php
include_once 'connect.php';
session_start();

$lastlogin=$_POST['lastlogin']

$datetime=date("d/m/y h:i:s");

$SQL="INSERT into players where lastlogin=$lastlogin (lastlogin) VALUE('$datetime');  ///or should i leave this (lastlogin) VALUE('$datetime'); out?///
$result=mysql_query($SQL) or die ("MySql Error");

session_destroy();
?>
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

Torniquet wrote:
SpiritWebb wrote:
Torniquet wrote:im pretty sure you need to have the include in there lol. as its trying to access a DB. in halls tut as far as i can remember he is not accessing any DBs.

stick the include in and see if it works :p
i did place the include_once, its in the above code, and it still doesnt work.
feel free to call me spasticated.... but i cannot see it lol
see: :P
SpiritWebb wrote:Here is the entire code:

I didnt change nothing with the code that halls provided with the tutorial. Except add the code in between session_start() and session_destroy(). I added the include_once 'connect.php'; command, and now I just get MySql Error
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: PHP Question

Post by hallsofvallhalla »

no you are missing a player session, but it would look like

Code: Select all

$sql="INSERT INTO players (lastlogin)VALUES('$datetime') where name='$session(player)'";
$result=mysql_query($sql) or die("MySql Error");
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

hallsofvallhalla wrote:no you are missing a player session, but it would look like

Code: Select all

$sql="INSERT INTO players (lastlogin)VALUES('$datetime') where name='$session(player)'";
$result=mysql_query($sql) or die("MySql Error");
Ok, I put what you had, and it wouldn't work, so I put this:

Code: Select all

$SQL="INSERT INTO players (lastlogin)VALUES('$datetime') where name='$lastlogin(player)'";  ///$session had an undefined index in $session///
$result=mysql_query($SQL) or die("MySql Error");
I changed $session to $lastlogin, and now it says undefined index, $lastlogin on line 17. Line 17 is: $lastlogin=$_POST['lastlogin']; Why is it telling me undefined, when it is defined?
Image

Image
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: PHP Question

Post by Torniquet »

im not sure about this... but i think where halls has put $session(player)

its ment to be $_SESSION(player)

repost all your code n we can have a look. because frankly all your different posting as editing without posting a new complete script is confusing :p
New Site Coming Soon! Stay tuned :D
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

Torniquet wrote:im not sure about this... but i think where halls has put $session(player)

its ment to be $_SESSION(player)

repost all your code n we can have a look. because frankly all your different posting as editing without posting a new complete script is confusing :p

Code: Select all

<?php
include_once 'connect.php';
  session_start();
  $lastlogin=$_POST['lastlogin'];
  $datetime=date("d/m/y h:i:s");

  $SQL="INSERT INTO players (lastlogin)VALUES('$datetime') where name='$_SESSION(player)'";
  $result=mysql_query($SQL) or die("MySql Error");

  session_destroy();
 
?>
Notice: Undefined index: lastlogin in C:\wamp\www\Mythuto\logout.php on line 17 MySql Error. Line 17 is $lastlogin=$_POST['lastlogin'];
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: PHP Question

Post by hallsofvallhalla »

activate the player session before calling it. My original code will work but you must either make it like $_SESSION(as t suggested)

or make a variable $player = $_SESSION(player);

there is not 17 lines in your code
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: PHP Question

Post by SpiritWebb »

hallsofvallhalla wrote:activate the player session before calling it. My original code will work but you must either make it like $_SESSION(as t suggested)

or make a variable $player = $_SESSION(player);

there is not 17 lines in your code

Code: Select all

<?php
include_once 'connect.php';
  session_start();
  $player=$_SESSION(player);
  $lastlogin=$_POST['lastlogin'];
  $datetime=date("d/m/y h:i:s");

  $SQL="INSERT INTO players (lastlogin)VALUES('$datetime') where name='$_SESSION(player)'";
  $result=mysql_query($SQL) or die("MySql Error");

  session_destroy();

?>
Fatal error: Function name must be a string on line 4
Image

Image
Post Reply

Return to “Coding”