Re: [PHP-DB] Need some help please!

2004-02-20 Thread Mikael Grön
Hi.

First of all it's never a good idea to use ? instead of ?php. But  
anyway. Your loss. ;)

You will need to do a refresh of the page to be able to run an insert  
query.
The refresh will need to be made by the JavaScript and since I've  
refused to learn JavaScript, I can't help you with that. Remember also  
that the JS needs to send a variable containing the username to the PHP  
code.

Now, I haven't had enough coffee today, so this is the best I can give  
you:
snip
	?php
		mysql_connect($hostname,$mysqluser,$mysqlpassword);
		$username = $_POST['user']; // What ever your JS will send the  
variable in.
		mysql_query(insert into score (user,date) values (' . $username .  
','.date(Y-m-d).'););
	?
/snip

Also, you might want to parse the username through a few str_replace's  
before you insert.. removing stuff like '' and ''.

Good luck!

Mikael

PS: I apparently sent this the first time using the wrong FROM  
address.. So here it comes again. ;)



On Feb 20, 2004, at 03:16, JeRRy wrote:

Hi,

I have this code, comments below:

? include(../pages/setup.php);?
? login();?
? include(../pages/header.php);?
!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01
Transitional//EN
html
head
STYLE
.general3 {background-color:#33;z-index:4}
.general2 {background-color:#55;z-index:3}
.general1 {background-color:#77;z-index:2}
.general0 {background-color:#99;z-index:1}
/STYLE  
title/title
/head
body
?
include(./config.phtml);
include(./$languagefile);
mysql_connect($hostname,$mysqluser,$mysqlpassword);
$query = select * from kras_params;;
$result = mysql_db_query($database,$query);
$row = mysql_fetch_array($result);
//fill vars
$total = $row[kr_total];
$chance = $row[kr_chance];
$maxwins = $row[kr_max_wins];
$wins = $row[kr_wins];
$timesaday = $row[kr_timesaday];
$host = $REMOTE_ADDR;
$check = 1;
$q_checktimes = select count(*) from kras_users where
usr_ip='$host' and usr_date=CURDATE();;
$checktimes_result =
mysql_db_query($database,$q_checktimes);
$times = mysql_fetch_row($checktimes_result);
$error = ;
if ($times[0]  $timesaday) {
//poging toevoegen in database
$raisetimes = insert into kras_users
values('$host',CURDATE(),'$HTTP_SESSION_VARS[username]');;
$raiseresult = mysql_db_query($database,$raisetimes)
or die('error: raise times failed');
} else {
$error .= LI$txt_maxplay $timesaday.;
$check = 0;
}
if ($wins == $maxwins) {
$error = LI$txt_maxwon;
$check = 0;
}
if ($check) {
//aantal malen dat spel gespeeld is ophogen met 1
$raisetotal = update kras_params set
kr_total=(kr_total+1);;
$raiseresult = mysql_db_query($database,$raisetotal);

if ($total%$chance == 0) {
$raisewins = update kras_params set
kr_wins=(kr_wins+1);;
$raisewinsresult =
mysql_db_query($database,$raisewins) or die('error:
raise wins failed');
$winner = 1;
}

?
	SCRIPT
	sc=new
Array('gfx/crown.jpg','gfx/x.jpg','gfx/seven.jpg','gfx/ 
diamond.jpg','gfx/ruby.jpg','gfx/magic.jpg');
	z=new Array();
	
	function check() {
		var oDivs = document.all.tags(DIV);
		for (i=0; ioDivs.length; i++){	
			
			var scratched = true;
			if (oDivs(i).style.display != none 
oDivs(i).scratchable == true) {
scratched = false;
return false;
			}
		}
		if (scratched == true)  {

?

echo ($winner ? alert(\$txt_youwon!
$HTTP_SESSION_VARS[username]\) :
alert(\$txt_youlost\));
			?

		}
	}	
			
	function rnd() {
		return Math.floor(Math.random()*sc.length);
	}
	
	?
	if ($winner) {
		echo function scimgload() {;
		echo document.scratch1.src=sc[rnd()];;
		echo document.scratch2.src=document.scratch1.src;;
		echo document.scratch3.src=document.scratch1.src;;
		echo };
	} else {
		echo function scimgload() {;
		echo document.scratch1.src=sc[rnd()];;
		echo document.scratch2.src=sc[rnd()];;
		echo document.scratch3.src=sc[rnd()];;
		echo while (document.scratch2.src ==
document.scratch3.src) {;
		echo document.scratch3.src=sc[rnd()];;
		echo };
		echo };
	}
	?
	function scmetal() {
	for (i=0;i192;i++)
	document.all['M'+i].style.display=;
	}
	/SCRIPT
	
	SCRIPT FOR=window EVENT=onload LANGUAGE=JScript
	  scimgload();
	/SCRIPT
	
	h1centerfont color=blueTMC Scratch n
Match/font/H1
	
	DIV scratchable=false STYLE=position:
relative;height: 300
	
	SCRIPT
	// This script must be within the relatively
positioned DIV.
	for (p=0;p3;p++)
	for (i=0;i4;i++)
	for (j=0;j4;j++)
	for (k=0;k4;k++) {
	idn=p*64+i*16+j*4+k;
	document.write('DIV scratchable=true ID=M'+idn+'
onmouseover=style.display=\'none\';check();
CLASS=general'+i+'
STYLE=position:absolute;width:25;height:25;top:'+eval(0+j*25)+'; 
left:'+eval(125+p*125+k*25)+'/DIV');
	}
	/SCRIPT
	IMG SRC= NAME=scratch1 ID=img1
STYLE=position:absolute;top:0;left:125;width:100;height:100;z-index: 
0
	IMG SRC= NAME=scratch2 ID=img2
STYLE=position:absolute;top:0;left:250;width:100;height:100;z-index: 
0
	IMG SRC= 

Re: [PHP-DB] Need some help please!

2004-02-20 Thread JeRRy
Mikael,

Hi :)

 First of all it's never a good idea to use ?
 instead of ?php. But  
 anyway. Your loss. ;)

My loss?  Explain?  (all ears)  I've used only ? php
a few times and end it with ? ...  But I normally use
only ? and ? and have *never* had a problem with it.
 

But I am all ears knowing why though?  I have seen
alot of different ones but have no idea what they mean
to be totally honest, here are some.

Starting codes:

?
? php 
? php else:
? php4 // I am guessing for php4 but could be wrong
//

 You will need to do a refresh of the page to be able
 to run an insert  
 query.
 The refresh will need to be made by the JavaScript
 and since I've  
 refused to learn JavaScript, I can't help you with
 that. Remember also  
 that the JS needs to send a variable containing the
 username to the PHP  
 code.

Bugger, can anyone else assist me here, the query part
I know how to do.  Just need help refreshing maybe to
the same file but use a if extension like this:

samefile.php?winner=WINNER CODE GOES HERE

WINNER CODE I could generate automatically when a game
is done, so if a winner it will update to the db with
the winner code and where someone hits the above page
it will look for that code again, if can't find it
will not generate the credits.  If it's found it will.

 Now, I haven't had enough coffee today, so this is
 the best I can give  
 you:

I've had none . :P  (yet!)

 Also, you might want to parse the username through a
 few str_replace's  
 before you insert.. removing stuff like '' and ''.

Actually I grab the username from a session in the
setup.php file. :)  So I can grab it quite easily.

 Good luck!

Thanks. :)

 PS: I apparently sent this the first time using the
 wrong FROM  
 address.. So here it comes again. ;)

Your not alone, happened to me also. ;)

Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php