ich habe heute wieder mit den coden angefangen (1 Jahr ca. her) und wollte ein einfaches script schreiben das bestimmt sachen in eine Datenbank schreibt doch leider klappt das nicht so ganz wie ich das will den er schreibt garnichts in die Datenbank und gibt mir auch keine Meldung aus. ich hoffe ihr könnt mir helfen ...
PHP Code:
include('sqlconnect.php');
Class Enemy
{
Private $Monstername;
Private $Monsterlevel;
Private $Monsterlife;
Private $Monsterimages;
Private $Monstermindmg;
Private $Monstermaxdmg;
Private $Auth = 0;
Function EnemyPastInfo($mName, $mLevel, $mLife, $mImages, $mMinDmg, $mMaxDmg)
{
$this->Monstername = $mName;
$this->Monsterlevel = $mLevel;
$this->Monsterlife = $mLife;
$this->Monsterimages = $mImages;
$this->Monstermindmg = $mMinDmg;
$this->Monstermaxdmg = $mMaxDmg;
}
Function EnemyExitsCheck($mName)
{
$sqlenemycheck = "SELECT * FROM monster_db WHERE Monstername='{$mName}'"; // SQL_QUERY
$enemycheck = $sqlcon->query($sqlenemycheck);
$enemycheckresult = $enemycheck->fetch_object();
if($mName == $enemycheckresult->Monstername)
{
echo '<font color="red"><b>Monster steht schon in der Datenbank</b></font>';
}else
{
$this->Auth = 1;
}
}
Function EnemyAdd()
{
if($this->Auth == 1)
{
$sqladdmonster = "INSERT INTO monster_db (Monstername, Monsterlevel, Monsterlife, Monstermindmg, Monstermaxdmg, Monsterimages) VALUES (?, ?, ?, ?, ?, ?)";
$addmonster = $sqlcon->prepare($sqladdmonster);
$addmonster->bind_param('issd', $this->Monstername, $this->Monsterlevel, $this->Monsterlife, $this->Monstermindmg, $this->Monstermaxdmg, $this->Monsterimages);
$addmonster->execute();
if($addmonster->affected_rows == 1)
{
echo '<font color="green">'.$this->Monstername.' hinzugefügt.</font>';
}else
{
echo '<font color="red">Fehler beim hinzufügen.</font>';
}
}else
{
echo '<font color="red"><b>Monster steht schon in der Datenbank</b></font>';
}
}
}
# ----------------------------------------------------------------------------------------------
// Formular : text_color;
$Color = '#FFFFD4;';
echo
'
<form action="#" method="post" style="background-color: #808080;">
<table>
<tr>
<td style="color:'.$Color.'">Monstername</td>
<td><input type="text" name="enemyname" /></td>
</tr>
<tr>
<td style="color:'.$Color.'">Monsterlevel</td>
<td><input type="text" name="enemylevel" /></td>
</tr>
<tr>
<td style="color:'.$Color.'">Monsterlife</td>
<td><input type="text" name="enemylife" /></td>
</tr>
<tr>
<td style="color:'.$Color.'">Monstermindmg</td>
<td><input type="text" name="enemymindmg" /></td>
</tr>
<tr>
<td style="color:'.$Color.'">Monstermaxdmg</td>
<td><input type="text" name="enemymaxdmg" /></td>
</tr>
<tr>
<td style="color:'.$Color.'">Monsterimages</td>
<td><input type="text" name="enemyimages" /></td>
</tr>
<tr>
<td><input type="submit" name="enemyadd" value="Monster-hinzufügen" /></td>
<td></td>
</tr>
</table>
</form>';
# Die Post-Results
$pName = $_POST['enemyname'];
$plevel = $_POST['enemylevel'];
$pLife = $_POST['enemylife'];
$pMindmg = $_POST['enemymindmg'];
$pMaxdmg = $_POST['enemymaxdmg'];
$pImages = $_POST['enemyimages'];
if(isset($_POST['enemyadd']))
{
if($pName == "" or $plevel == "" or $pLife == "" or $pMindmg == "" or $pMaxdmg == "" or $pImages == "")
{
echo '<font color="red">Bitte alle felder ausfüllen.</font>';
}else
{
$EnemyAdd = new Enemy();
$EnemyAdd->EnemyPastInfo($pName, $pLevel, $pLife, $pImages, $pMindmg, $pMaxdmg);
$EnemyAdd->EnemyExitsCheck($pName);
$EnemyAdd->EnemyAdd();
}
}
?>






