Simple PHP things for your site :P

Joined
Jul 16, 2008
Messages
861
Reaction score
25
Send item Code
Ok, first copy the first code and open your notepad and save as item.php
The second code copy it and save as config.php

item.php you see the Red Option Things just add 1 more row with another value and name or edit. The Value is the ItemID you want they choose. Just search in your zitem.xml ;)
Code:
<FORM method="post" action="<? echo $PHP_SELF;?>">
<p>Characternaam:
<input name="aid" type="textfield" />
<select name="sg">
[COLOR="Red"]<option value="33334">Donatie Shotgun 1</option>
<option value="33354">Donatie Shotgun 2</option>
<option value="33359">Donatie Shotgun 3</option>[/COLOR]
</select>
<input type="submit" value="koop" name="koop" />
</form>
<?
include('config.php');
$naam = anti_injection($_POST ["aid"]);
$itemid = anti_injection($_POST ["sg"]);
$cid = ("SELECT CID FROM Character where Name='$naam'");
$query = odbc_exec($connect,$cid);
odbc_fetch_row($query);
$cidnr = odbc_result($query, 1);
if (isset($_POST["koop"]))
{
if (empty($naam))
{
echo ('<br>Je moet een Characternaam invullen!');
}
else
{
echo ('<br>Succesvol gekocht!');
odbc_exec ($connect, "INSERT INTO CharacterItem (CID, ItemID) VALUES ('$cidnr', '$itemid')"); 
}
}
?>

config.php
Code:
<?
$host = "[COLOR="Red"]HYLPER\SQLEXPRESS[/COLOR]"; // [COLOR="Red"]your sql server[/COLOR]
$dbname = "[COLOR="Red"]GunzDB[/COLOR]"; // [COLOR="Red"]Your db name[/COLOR]
$user = "[COLOR="Red"]sa[/COLOR]"; // [COLOR="Red"]your sql inlogname[/COLOR]
$pass = "[COLOR="Red"]yourpw[/COLOR]"; // [COLOR="Red"]your db password[/COLOR] 
$connect = odbc_connect("Driver={SQL Server};Server={$host}; Database={$dbname}", $user, $pass) or die("Kan niet verbinding maken met de Server.");
function anti_injection($sql)
{
$sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$sql);
$sql = trim($sql);
$sql = strip_tags($sql);
$sql = addslashes($sql);
return $sql;
} 
?>



Another easy php code. Just copy and save as search.php or something :P But it needs to be in the same map as the config.php
Code:
<form method="post" action="<? echo $PHP_SELF;?>">
  <p><b>Characternaam:</b>
      <input type="text" name="char" />
  </p>
  <p>
    <input type="submit" value="zoek" name="zoek" />
  </p>
  </form>
<?
include ('config.php');
$char = $_POST["char"];
$sql = ("SELECT Name,Level,XP,KillCount,Deathcount,Regdate,bp,sex FROM Character (nolock) where name='$char'");
$query = odbc_exec($connect,$sql);
odbc_fetch_row($query);
$sex = odbc_result($query, 8);

if( isset($_POST['zoek']) )
            {
                        if (empty ($char))
                        {
echo("<font color=\"red\"><h1>U hebt niks ingevuld!</h1></font>");
}
else
{                       echo ('<b>Naam: ');
                        echo odbc_result($query, 1);
                        echo ('<br>');
                        echo ('Level: ');
                        echo odbc_result($query, 2);
                        echo ('<br>');
                        echo ('XP: ');
                        echo odbc_result($query, 3);
                                                echo ('<br>');
                        echo ('Killz: ');
                        echo odbc_result($query, 4);
                                                echo ('<br>');
                        echo ('Dood: ');
                        echo odbc_result($query, 5);
                                                echo ('<br>');
                                                echo ('Geld: ');
                        echo odbc_result($query, 7);
                        echo ('<br>');
echo ('Aangemaakt om: ');
                        echo odbc_result($query, 6);
                                                echo ('<br>');
echo ('Geslacht: ');
                        if($sex=="1")
{
echo ('Woman');
}
elseif ($sex=="0")
{
echo ('Man');
}

                        }
                        }
?></b>
This is just some basics don't blame me xd if i made a mistake just say it.
 
Back