Wow, thanks for the explanation and the code. This is exactly what I'm trying to accomplish and am thankful I'm at least on the right track. I'm going to do more reading and then I'll revisist and rewrite the game. When I've redone it, I'll compare it to yours. Thanks again.

Ok, is this better?

<!DOCTYPE HTML>
<head>
<script>

function ogreattack(){
var gameon=confirm("Would you like to fight an ogre?");

while (gameon==true){
var pmove=prompt("Do you want to stab, punch or run?");

switch (pmove){
        case "stab":
        stabbing();
        ogremove();
        break;
        case "punch":
        punching();
        ogremove();
        break;
        case "run":
        running();
        break;
        case "":
    ogreattack();
    break;
}
}   
}
function stabbing(){
var stab=Math.floor(Math.random()*500);
var deflect=Math.floor(Math.random()*10);
var ogrelife=400;
    if (deflect>7){
        document.write('You have stabbed the Ogre and dealt ' + stab + ' damage<br>');
            if (stab>=ogrelife){
                document.write('You have killed the Ogre<br>');
        return ogreattack();}}
    else{
        document.write('Your attack was deflected<br>');}}
function punching(){
var punch=Math.floor(Math.random()*200);
var deflect=Math.floor(Math.random()*10);
var ogrelife=200;
    if (deflect>4){
        document.write('You have punched the Ogre and dealt ' + punch + ' damage<br>');
            if (punch>ogrelife){
                document.write('You have knocked out the Ogre<br>');
        return ogreattack();}}
    else{
        document.write('Your punch was deflected<br>');}}
function running(){
var run=Math.floor(Math.random()*2000);
    if (run>1000){
        document.write('You have ran away and lost the fight<br>');
        return ogreattack();}
    else{
        document.write('Your escape was blocked<br>');
        ogremove();}}
function ogremove(){
var life=100;
var hit=Math.floor(Math.random()*1000);
    if (hit>300){
        var damage=Math.floor(Math.random()*1000);
    document.write('You have been hit.  The Ogre caused ' + damage +  ' damage to you<br>');
        var life=-damage;   
                if (life<=0){
                document.write('You have died<br>');
                return ogreattack();}}
    else{
        document.write('The Ogre missed you<br>');}

window.location.href="http://stackoverflow.com/questions/7077770/window-location-href-and-window-open-methods-in-javascript";
}

</script>
</head>
<body onload="ogreattack()">

</body>
</html>

Some problems with window.location (it doesn't work) and the "stab" function doesn't work quite right but I think it's better.

The game, and my site, is more of an attempt to get good at programming than anything else. This particular game is practice with Math.random and Math.floor as they relate to decision making, versus just giving out a number. I wanted everything to be random, with a ceiling, because the amount of damage you would inflict on anything is unpredictable until you have struck it but there is a ceiling to the amount of damage an action can inflict.

As I barely know what I'm doing, I totally appreciate your comments and feedback and will keep them in mind. It's much better to read your last comment, than just the correction to the code.

That's what I'd like to do, subtract from both based on the hp lost but I can't figure out how to do it. I figured out how to fix the players life, and the game now ends when life >= 0, but I can't get the other part to work.

Here is the code with the math in it.

<!DOCTYPE HTML>
<head>
<script>
var life=100;
var ogrelife=2000;

function ogreattack(){

while (ogrelife>0){
var pmove=prompt("Do you want to stab, punch or run?");
switch (pmove){

    case "stab":
    stabbing();
    ogremove();
    break;
    case "punch":
    punching();
    ogremove();
    break;
    case "run":
    running();
    break;}

}   

}

function stabbing(){

var stab=Math.floor(Math.random()*2500);
var deflect=Math.floor(Math.random()*10);

    if (deflect>7){
        document.write('You have stabbed the Ogre and dealt ' + stab + ' damage<br>');
            if (stab>ogrelife){
                document.write('You have killed the Ogre<br>');}}
    else{
        document.write('Your attack was deflected<br>');}}

function punching(){

var punch=Math.floor(Math.random()*2000);
var deflect=Math.floor(Math.random()*10);

    if (deflect>4){
        document.write('You have punched the Ogre and dealt ' + punch + ' damage<br>');
            if (punch>ogrelife){
                document.write('You have knocked out the Ogre<br>');}}
    else{
        document.write('Your punch was deflected<br>');}}

function running(){

var run=Math.floor(Math.random()*2000);

    if (run>1000){
        document.write('You have ran away and lost the fight<br>');
        }
    else{
        document.write('Your escape was blocked<br>');
        ogremove();}}

function ogremove(){

var hit=Math.floor(Math.random()*1000);

    if (hit>300){
        var damage=Math.floor(Math.random()*1000);
        document.write('You have been hit.  The Ogre caused ' + damage +  ' damage to you<br>');
        var life=life-damage;   
                if (life=0){
                document.write('You have died');
                return;}}
    else{
        document.write('The Ogre missed you<br>');}}

</script>
</head>
<body onload="ogreattack()">

</body>
</html>

Hi all. I'm writing my first javascript game. It's a role playing game where the user fights an Ogre, and not elaborate at all. I'd like the game to end when the Ogre's life is at zero OR the users life is at zero. I can't figure out how to have the program keep track of the amount of damage the user and the Ogre inflict on each other. Any ideas? Also, if this has been asked before, please point me in the direction of the completed discussion and I'll look it up there. Thanks.

<!DOCTYPE HTML>
<head>
<script>
var life=100;
var ogrelife=2000;

function ogreattack(){

while (ogrelife>0){
var pmove=prompt("Do you want to stab, punch or run?");
switch (pmove){

    case "stab":
    stabbing();
    ogremove();
    break;
    case "punch":
    punching();
    ogremove();
    break;
    case "run":
    running();
    break;}

}   

}

function stabbing(){

var stab=Math.floor(Math.random()*2500);
var deflect=Math.floor(Math.random()*10);

    if (deflect>7){
        document.write('You have stabbed the Ogre and dealt ' + stab + ' damage<br>');
            if (stab>ogrelife){
                document.write('You have killed the Ogre<br>');}}
    else{
        document.write('Your attack was deflected<br>');}}

function punching(){

var punch=Math.floor(Math.random()*2000);
var deflect=Math.floor(Math.random()*10);

    if (deflect>4){
        document.write('You have punched the Ogre and dealt ' + punch + ' damage<br>');
            if (punch>ogrelife){
                document.write('You have knocked out the Ogre<br>');}}
    else{
        document.write('Your punch was deflected<br>');}}

function running(){

var run=Math.floor(Math.random()*2000);

    if (run>1000){
        document.write('You have ran away and lost the fight<br>');
        return;}
    else{
        document.write('Your escape was blocked<br>');
        ogremove();}}

function ogremove(){

var hit=Math.floor(Math.random()*1000);

    if (hit>300){
        var damage=Math.floor(Math.random()*1000);
        document.write('You have been hit<br>');}
    else{
        document.write('The Ogre missed you<br>');}}

</script>
</head>
<body onload="ogreattack()">

</body>
</html>

try changing the size in your input box? You have it set to 50 characters.

<label>Name : </label><input type='text' name='event_n' ***size='50'*** value='$name'>";

Is it connecting to the database?

Have you checked to see if php is installed and running? If not, create this script and run it from your browser.

<?php
phpinfo();
?>

Check your database. Is the date column set to "date" and/or did you make it big enough to display what you want?

diafol commented: good thinking +14

Here is a link to Tutorial Point

There are a lot of tutorials out there. I used an "UPDATE" command on my site. For example:

mysqli_query("UPDATE registration SET name='$name', dob='$dob', userid='$userid', sex='$sex', family='$family', describe='$describe', pic='$pic' WHERE name='$name'");

The best way to see if it will work is to try it. I don't think you'll have a problem with it because it is not pointing to the same root.

Got it. Here is the final php code. I needed to open and close the tags in the loop. Thanks for the idea, as you can see I incorporated most of what you did in the final code.

<?php require('connect/registerdb.php');

echo '<select name="respondto">';

$query=mysqli_query($rcon,"SELECT userid FROM registration");
while ($row=mysqli_fetch_array($query)){

echo '<option name="to">' . $row['userid'] . '</option>';}
echo '</select>';
?>

No, still showed rountest instead of
roun
test

It seems t me that you can't use the session like you want. Can you just put a link to what you want and use that to create the session? You could have people agree to the terms of use and then, using that information, create your session.

if (isset($terms_of_use))
{
session_start();
echo 'ss';}

More of a question than anything.

Are you asking to show data in the session before you enter the data?

I want to be able to show some .php files before the user logs in
I know that the reason we do the session is for ones who are users to see the files but is it possible.

Ok, so this is cool. On my site, I learned how to create a simplified "wall" like facebook has... sort of. It's great for me to have done that because I am self taught with all of this. There is a problem, however. My is not displaying the names correctly. It should display each name listed in the database separately, instead it is showing displaying them as a runon sentence. I don't understand why the
command isn't working. Here is the php:

<?php
$query=mysqli_query($rcon,"SELECT userid FROM registration");
while ($row=mysqli_fetch_array($query)){
echo $row['userid'] . '<br>';}
?>

and here is the other code

<?php

include('php/wall.php');

?>
<form name="response" action="messages/enterblog.php" method="POST">
To:<select name="respondto">
<option name="to"><?php require('connect/registerdb.php'); include('messages/list.php');?></option>
</select>
Message:<input type="text" name="respond">
<input type="submit">
</form>
</div>

Here is what is displayed.
rountest

as opposed to
roun
test

Alright, it works on my live site but not on XAMPP. Must be an XAMPP problem.

No, sorry. It didn't fix it.

Click Here for a link on uploading a file to a folder. You should only use the database as a pointer.

You might want to check your spelling, in both the database and the table. Everytime that happens to me, it's because I misspelled something. You might also try renaming them to GroupMgt and FileUploadsLog. Underscores are legal according to Click Here

So, when I run this code on xampp, it works and I can see the variables, without the header.

<html>
<head>
</head>
<body>
<?php
$user="";
$server="";
$db="";
$pass="";
$con=mysqli_connect($server,$user,$pass,$db);

$id=$_POST['loginid'];
$password=md5($_POST['password']);

$result=mysqli_query($con,"SELECT * FROM passwords WHERE userid='$id' AND password='$password'");
session_start();
if($row=mysqli_fetch_array($result)){
require('../connect/registerdb.php');
$rresult=mysqli_query($rcon,"SELECT * FROM registration WHERE userid='$id'");
while($rrow=mysqli_fetch_array($rresult)){

$_SESSION['name']=$rrow['name'];
$_SESSION['dob']=$rrow['dob'];
$_SESSION['userid']=$rrow['userid'];
$_SESSION['sex']=$rrow['sex'];
$_SESSION['family']=$rrow['family'];
$_SESSION['describe']=$rrow['describe'];
$_SESSION['pic']=$rrow['pic'];
$_SESSION['visibility']=$rrow['visibility'];
$_SESSION['registeredon']=$rrow['registeredon'];
$_SESSION['lastlogin']=$rrow['lastlogin'];
require('../connect/emaildb.php');
$eresult=mysqli_query($econ,"SELECT email FROM emaillist WHERE userid='$id'");
while($erow=mysqli_fetch_array($eresult)){
$_SESSION['email']=$erow['email'];
}
}
header('Location:../mainpage.php');
}
?>
</body>
</html>

When I add the header, I get:

Notice: Undefined index: loginid in C:\xampp\htdocs\website\session\session.php on line 12

Notice: Undefined index: password in C:\xampp\htdocs\website\session\session.php on line 13

Why does it work without the header but not with the header?

Ok, so here is what it says in the console:

Resource interpreted as Image but transferred with MIME type image/tiff: "http://localhost/website/pages/n/larva%20%20Keara.tiff".

So, I changed the image to a jpg and changed the pointer in the database. That note went away but this remained:

GET http://localhost/website/bground.css 404 (Not Found)

<!DOCTYPE HTML>
<html>
<head>
<meta name="keywords" content="Roun, David Roun, Rounsworld, Heather Roun">
<meta name="description" content="Personal website">
<meta name="author" content="David Roun">
<meta charset"UTF-8">

<link rel="stylesheet" type="text/css" href="bground.css"> <!---this is where the CSS file is being called---!>
</head>
<body>
<?php session_start();?>
<div id="header">
<table>
<tr><td><img id="hedr"  src="pages/<?php echo $_SESSION['name'] . '/' . $_SESSION['picture'];?>"/></td><td id="nme"><?php echo $_SESSION['name'];?></td></tr>   
</table>
</div>
</body>
</html>

It worked right when I put the full path in but I'm wondering if there is another fix (I'm lazy).

That't what I thought and checked 4 times. I may just need to keep it on the same page but I want that to be the background for multiple pages and don't want to have to keep using the same code. Tried to attach a screenshot of the folder but couldn't.

Ok, so here is the CSS code in an external sheet:

#header{
position:fixed;
width:100%;
height:15%;
}
#hedr{
position:fixed;
height:5%;
width:6%;
top:5%;
left:30%;}
#nme{
position:fixed;
font-size:400%;
top:3%;
left:10%;
}

Here is the php document:

<!DOCTYPE HTML>
<html>
<head>
<meta name="keywords" content="Roun, David Roun, Rounsworld, Heather Roun">
<meta name="description" content="Personal website">
<meta name="author" content="David Roun">
<meta charset"UTF-8">

<link rel="stylesheet" type="text/css" href="bground.css">
</head>
<body>
<?php session_start();?>
<div id="header">
<table>
<tr><td><img id="hedr"  src="pages/<?php echo $_SESSION['name'] . '/' . $_SESSION['picture'];?>"/></td><td id="nme"><?php echo $_SESSION['name'];?></td></tr>   
</table>
</div>
</body>
</html>

The problem is that the CSS code works when it is on the same page as the php file, but when I try to use it as an external sheet, the page ignores it and displays the picture full page. I tried it in the same folder, and in a different folder (originally) and had the CSS code checked, so I know it's not the code. Any thoughts?

Perfect. Thank you so much

Same thing. I'm totally at a loss.

No go. Same error message. I can't find a problem with it, or the code around it.

<?php
$name=trim(mysql_real_escape_string($_POST['name']));

require('../connect/kidsblogsconnect.php');
mysql_query("CREATE TABLE $name(sender VARCHAR(30), message VARCHAR(300), dateposted DATE)") or DIE(mysql_error());

?>

How come you are using 2 echo commands?