Jump to content

Pi_Mastuh

Members
  • Posts

    233
  • Joined

  • Last visited

    Never

Posts posted by Pi_Mastuh

  1. I've got the cookie creating part:

    [code]$expire = time()+60*60*24*365; // Expire in 1 year
     
      setcookie("preuserID", "$preuserID", $expire);
      setcookie("preuserPassword", "$password", $expire);

    header("Location: ../home.php");
    exit;[/code]

    and the fetching:

    [code]<?
    if(isset($_COOKIE['preuserID']) && !empty($_COOKIE[';preuserID']) and
    isset($_COOKIE['preuserPassword']) && !empty($_COOKIE[';preuserPassword']))
    {
      // your cookie is found
      $preuserID = htmlspecialchars($_COOKIE['preuserID'], ENT_QUOTES);
      $preuserPassword = htmlspecialchars($_COOKIE['preuserPassword'], ENT_QUOTES);

      header(Location: /reg/home.php);
      exit();
    }
    ?>[/code]

    which is imbeded in my index.htm, but it's not redirecting. Anyone know why?
  2. I want to make my site save a session so the user doesn't need to login everytime they com to the site. If they've logged in previously I want them to still be login when they go to my site and it will re-direct to a certain page if they're logged in. Anyone know how to do that?
  3. I'm working on a dual arena for my site where users can fight against the computer. This is the page that does all the calculations and stuff then updates the data in the database and goes to another page based on results. It's kind of hard to explain. All my echos are coming back as 0 and it's not re-directing to another page, anyone know what's wrong?

    [code]<?php
    //Database
    include ("config.php");
    session_start();
    $session = session_id();

    $db_name = "db175253437";

    $conn = mysql_connect("db491.perfora.net", "****" ,"****", true) or die("Couldn't connect");

    mysql_select_db($db_name, $conn) or die("Couldn't select Database1.");


    $SQL = "SELECT * FROM CurrentFights WHERE userID = '".$_POST['preuserID']."'";
    $result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
    $numberF = mysql_num_rows($result);
    $query_data = mysql_fetch_array($result);
    $turn = $query_data['turn'];
    $petID2 = $query_data['petID'];
    $cID2 = $query_data['cID'];

    $SQL = "SELECT * FROM LastRound WHERE userID = 'preuserID'";
    $result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
    $numberF = mysql_num_rows($result);
    $query_data = mysql_fetch_array($result);
    $pLDmg = $query_data['pDmg'];
    $cLDmg = $query_data['cDmg'];

    $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '".$_POST['monopetID']."'";
    $result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
    $query_data = mysql_fetch_array($result);
    $hp = $query_data['hp'];
    $totalHP = $query_data['totalHP'];
    $lvl = $query_data['monopetLevel'];
    $xp = $query_data['xp'];
    $petName = $query_data['monopetName'];

    $SQL = "SELECT * FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'";
    $result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
    $query_data = mysql_fetch_array($result);
    $atkValue = $query_data['atkValue'];
    $defValue = $query_data['defValue'];
    $itemName = $query_data['itemName'];

    $SQL = "SELECT * FROM Challengers WHERE cID = '".$_POST['cID']."'";
    $result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
    $query_data = mysql_fetch_array($result);
    $cHP = $query_data['cHP'];
    $cLvl = $query_data['cLvl'];
    $cName = $query_data['cName'];
    $cWepVal = $query_data['cWepVal'];

    $SQL = "SELECT * FROM CurrentFights WHERE userID = 'preuserID'";
    $result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
    $numberF = mysql_num_rows($result);
    $query_data = mysql_fetch_array($result);
    $cCurHP = $query_data['cHP'];

    //Get the damage ammount
    $max = $lvl+$atkValue;
    $dmg1 = rand(0, $max);
    $dmg2 = rand(0, $max);
    echo "Max: $max<br>dmg1: $dmg1<br>dmg2: $dmg2";
    //What kind of attack are they doing - figure out their damage
    if ($atkType == "Fierce")
    {
    $dmg = $dmg1 + $dmg2;
    }
    elseif ($atkType == "Cautious")
    {
    if ($dmg1 > $dmg2)
    {
    $dmg = $dmg1;
    }
    elseif ($dmg1 < $dmg2)
    {
    $dmg = $dmg2;
    }
    elseif ($dmg1 == $dmg2)
    {
    $dmg = $dmg1;
    }
    $def = $lvl;
    }
    elseif ($atkType == "Defensive")
    {
    if ($dmg1 > $dmg2)
    {
    $dmg = $dmg1-$dmg2;
    }
    elseif ($dmg1 < $dmg2)
    {
    $dmg = $dmg2-$dmg1;
    }
    elseif ($dmg1 == $dmg2)
    {
    $dmg = 0;
    }
    $def = $lvl*2;
    }
    else
    {
    echo "Error: Invalid attack type";
    }
    echo "dmg: $dmg<br>def: $def";

    //Opponent's dmg
    $max2 = $cLvl+$cWepVal;
    $Cdmg1 = rand(0, $max2);
    $Cdmg2 = rand(0, $max2);
    $CType = rand(1, 3);
    echo "max2: $max2<br>cdmg1: $Cdmg1<br>cdmg2: $Cdmg2<br>ctype: $ctype";

    if ($CType == "3")
    {
    $Cdmg = $Cdmg1 + $Cdmg2;
    }
    elseif ($CType == "2")
    {
    if ($Cdmg1 > $Cdmg2)
    {
    $Cdmg = $dCmg1;
    }
    elseif ($Cdmg1 < $Cdmg2)
    {
    $Cdmg = $Cdmg2;
    }
    elseif ($Cdmg1 == $Cdmg2)
    {
    $Cdmg = $Cdmg1;
    }
    $Cdef = $cLvl;
    }
    elseif ($CType == "1")
    {
    if ($Cdmg1 > $Cdmg2)
    {
    $Cdmg = $Cdmg1-$Cdmg2;
    }
    elseif ($Cdmg1 < $Cdmg2)
    {
    $Cdmg = $Cdmg2-$Cdmg1;
    }
    elseif ($Cdmg1 == $Cdmg2)
    {
    $Cdmg = 0;
    }
    $Cdef = $cLvl*2;
    }
    else
    {
    echo "Error: Invalid attack type for opponent";
    }

    echo "Cdmg: $Cdmg<br>Cdef: $Cdef";
    //find out the final result
    if ($dmg > $Cdef)
    {
    $Pdmg = rand($Cdef, $dmg);
    }
    elseif ($dmg < $Cdef)
    {
    $Pdmg = rand($dmg, $Cdef);
    }
    elseif ($dmg == $Cdef)
    {
    $Pdmg = $dmg;
    }

    if ($Cdmg > $def)
    {
    $Ctdmg = rand($def, $Cdmg);
    }
    elseif ($Cdmg < $def)
    {
    $Ctdmg = rand($Cdmg, $def);
    }
    elseif ($Cdmg == $def)
    {
    $Ctdmg = $Cdmg;
    }

    $turn++;
    $newHP = $hp-$Ctdmg;
    $cnewHP = $cCurHP-$Pdmg;
    if ($newHP > 0 and $cnewHP > 0)
    {
    mysql_query("UPDATE CurrentFights SET turn = '$turn' WHERE userID = '$preuserID'");
    mysql_query("UPDATE CurrentFights SET cHP = '$cnewHP' WHERE userID = '$preuserID'");
    mysql_query("UPDATE chibifriendspets SET hp = '$newHP' WHERE monopetID = '$monopetID'");
    mysql_query("UPDATE LastRound SET pDmg = '$Pdmg' WHERE userID = '$preuserID'");
    mysql_query("UPDATE LastRound SET cDmg = '$Ctdmg' WHERE userID = '$preuserID'");

    header("Location:arena4.php");
    }
    elseif ($newHP <= 0 and $cnewHP <= 0)
    {
    $fight = "Draw";
    header("Location:arena6.php");
    }
    elseif ($newHP <= 0 and $cnewHP > 0)
    {
    $fight = "Lose";
    header("Location:arena6.php");
    }
    elseif ($newHP > 0 and $cnewHP <= 0)
    {
    $fight = "Win";
    header("Location:arena6.php");
    }
    ?> [/code]
  4. I'm working on my messaging system and when you reply I have it add RE: to the subject, however now there're messages that're RE:RE:RE:RE:RE:RE:___ etc, Is there a way for it to tell it to add RE: only if it's not there?
  5. Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    Here's my full code:

    [code]<?
    session_start();
    $session = session_id();
    include ("secure/config.php");
    include ("secure/dbinfo.php");

    $msgID = $_POST['msgID'];
    echo $msgID;

    mysql_query("DELETE FROM `Mail` WHERE `msgID` = '$msgID'") or die(mysql_error());

    header("Location:../inbox.php");

    ?>[/code]
  6. I'm using

    mysql_query("DELETE FROM `Mail` WHERE `msgID` = '$msgID'");

    but it's not deleting. The variable works, I'm echoing it at the top of the page, but for some reason it won't delete. When I actualy put

    DELETE FROM `Mail` WHERE `msgID` = '12'

    into the database it works just fine. Any ideas as to what's wrong?
  7. I'm running a query that when you load the page it changes Read from 0 to 1 if it's 0. And I got the following error:

    The query: UPDATE Mail SET read = '1' WHERE msgID = '1' Caused the following error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'read = '1' WHERE msgID = '1'' at line 1
  8. I'm running this query:

    $SQL = "UPDATE Mail SET read = '1' WHERE msgID = '$msgID'";
    $result2 = mysql_query($SQL, $connection);

    but nothing's happening. I try running the query on its own and substituing $msgID with an actualy number, but it says the query is wrong. Any ideas as to what's wrong?
  9. The page I'm making displays each of the user's pets and some of the data. The Item that's equipped is stored in a different table so I copied the code exactly except changed the table stuff. However it's returning that 2 pets have an item equipped, which is correct. Except it's the wrong two pets, and it's not showing the third pet at all. It should be 1 with no item, 2 and 3 with items but it's returning 1 and 2 with items and not #3 at all. Here's my code.

    [code]<?

    //Databasing Stuff
    include ("config.php");
    session_start();
    $session = session_id();

    $db_name = "db175253437";

    $conn = mysql_connect("db491.perfora.net", "****" ,"****", true) or die("Couldn't connect");

    mysql_select_db($db_name, $conn) or die("Couldn't select Database1.");



    //End Databasing Stuff

    ?>
    <p align=center><? echo "Which pet would you like to send into batte:";?><br><br><a href='../forest.php'>Back to the Kriegit Forest</a><br><br><table width="480" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="4">&nbsp;</td>
            </tr>
            <tr bgcolor="ebebeb">
              <td width="120"><div align="center"><b><font size="2" face="Arial, Helvetica, sans-serif">Picture</font></b></div></td>
              <td width="120" bgcolor="ebebeb" valign="top">
                <div align="center"><font size="2"><b><font face="Arial, Helvetica, sans-serif">Name</font></b></font></div></td>
              <td width="120">
                <div align="center"><font size="2"><b><font face="Arial, Helvetica, sans-serif">Species</font></b></font></div></td>
              <td width="120">
                <div align="center"><font size="2"><b><font face="Arial, Helvetica, sans-serif">Equipment</font></b></font></div></td>
            </tr>
          </table>
          <?
     
       $SQL = "SELECT * FROM chibifriendspets WHERE monopetID = '".$_POST['monopetID']."'";

    $result1 = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");

    $query_data = mysql_fetch_array($result1);

    $query = "SELECT * FROM chibifriendspets WHERE userID = '$preuserID'";

    $result4 = mysql_query($query, $connection);

    $numberPETS = mysql_num_rows($result4);

    $query_data = mysql_fetch_array($result4);

    $monopetID = $query_data['monopetID'];
    $monopetName = $query_data['monopetName'];

    $monopetSpecies = $query_data['monopetSpecies'];

    $monopetDOB = $query_data['monopetDOB'];



    $SQL = "SELECT * FROM Dualequip WHERE petID = '".$_POST['monopetID']."'";

    $result2 = mysql_query($SQL, $connection) or die("Error2: ".mysql_error()."");

    $query_data = mysql_fetch_array($result2);

    $query = "SELECT * FROM Dualequip WHERE preuserID = '$preuserID'";

    $result5 = mysql_query($query, $connection);

    $numberPETS = mysql_num_rows($result5);

    $query_data = mysql_fetch_array($result5);

    $itemName = $query_data['itemName'];

    $itemID = $query_data['itemID'];

    $i = 0;



    if ($numberPETS < 1)
    {

    print "<CENTER>You don't have any petz!</CENTER>";

    }

    else {

    while ($numberPETS > $i) {

    //$monopetImage1 = mysql_result($result2,$i,"monopetImage1");

    $monopetName = mysql_result($result4,$i,"monopetName");

    $monopetSpecies = mysql_result($result4,$i,"monopetSpecies");

    $monopetDOB = mysql_result($result4,$i,"monopetDOB");

    $monopetID = mysql_result($result4,$i, "monopetID");





    print "

    <table width=480 border=0 cellspacing=0 cellpadding=0><tr><td width=180><form method=POST action=petDetails2.php>

    <input type=hidden name=monopetID value=$monopetID>

    <input type=image src=$monopetSpecies.jpg></FORM></td>

    <td width=120 valign=middle><div align=center><font face=Arial, Helvetica, sans-serif size=2>$monopetName</font></div></td>

    <td width=120 valign=middle><div align=center>$monopetSpecies</div></td>

    <td width=120 valign=middle><div align=center>$itemName</div><td></td></td>

    </tr></table>";



    $i++;

    }

    }





    ///////







    ?>
    [/code]

    Thanks! :)
  10. I'm using this:
    [code]$sql = "SELECT count(*) as atkItem FROM Dualequip WHERE petID = '$monopetID'";
      $result1 = mysql_query($sql);
    $query_data = mysql_fetch_array($result1);
    $atkItem = $query_data['atkItem'];

    if ($atkItem > 0)
    {
    $SQL = "SELECT * FROM Dualequip WHERE petID = '$monopetID'";
    $result = mysql_query($SQL, $connection) or die("Error: ".mysql_error()."");
    $query_data = mysql_fetch_array($result);
    $atkValue = $query_data['atkValue'];
    $defValue = $query_data['defValue'];
    if ($atkValue > 0)
    {
    $no = 0;
    }
    elseif ($defValue > 0)
    {
    $no = 1;
    }
    else
    {
    $no = 3;
    }
    }[/code] and [code]if ($no == 0 AND $food == "Weapon" AND $atkValue > o)
    {
    echo "<p align=center>$monopetName already has an attack item equipped!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
    }
    elseif ($no == 1 AND $food == "Weapon" AND $defValue > o)
    {
    echo "<p align=center>$monopetName already has an defense item equipped!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
    }
    elseif ($food == "Weapon")
    {
    $sql = "INSERT INTO Dualequip (preuserID, petID, itemID, atkValue, defValue)
    VALUES ('$preuserID', '$monopetID', '$itemID', '$atkValue', '$defValue')";
    mysql_query("DELETE FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'");

    $result = mysql_query($sql) or die("There was an error equiping the weapon. Sorry.");
    echo "<p align=center>You have equipped <b>".$monopetName."</b> with <b>".$itemName."</b>!<br><br><a href='../myitems.php'>Back to Your Inventory</a>";
    }[/code] but the pet i'm using to test has 3 items equipped when it should only be 1. It's not blocking it.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.