So also hier der Quelltext der config.php:
PHP-Code:
class content{
private $connection = NULL;
private $result = NULL;
public function connect() {
$host = "localhost";
$db = "test";
$user = "sel";
$passw = "****";
$this->connection = mysql_connect ("$host", "$user", "$passw");
if($this->connection != false){
mysql_select_db("$db", $this->connection);
}else{
exit;
}
}
public function disconnect() {
if (is_resource($this->connection)) {
mysql_close($this->connection);
}
}
public function query($query,$quest) {
$this->connect();
if (is_resource($this->connection)) {
if (is_resource($this->result)) {
mysql_free_result($this->result);
}
$this -> result = mysql_query($query,$this->connection);
echo mysql_error();
switch($quest){
case "assoc":
if (is_resource($this->result)) {
if (mysql_num_rows($this->result) > 1){
$count = 1;
while($row = mysql_fetch_assoc($this->result)){
$ergrow[$count] = $row;
$count++;
}
return $ergrow;
}else{
$row = mysql_fetch_assoc($this->result);
if (is_array($row)) {
return $row;
} else {
return FALSE;
}
}
}
break;
case "num_rows":
if (is_resource($this->result)) {
$row = mysql_num_rows($this->result);
return $row;
}
break;
}
}
$this -> disconnect();
}
In der index.php die fürs Layout zuständig ist stehen in den ersten Zeilen nur:
PHP-Code:
<?php
include "texte/config.php";
$cont = new content;
?>
Dann kommt HTML.
Da wo der Inhalt der SQL DB rein soll steht:
PHP-Code:
$text = $cont->query("SELECT * FROM `test` WHERE name=\"Daniel\"","assoc");
echo $text["text"];
include "texte/regform.php";
So der Inhalt der regform.php ist noch nicht großartig ausgeprägt aber es soll in der DB überprüft werden ob ein best. Name vorhanden ist.
PHP-Code:
$usrindb = $cont->query("SELECT user FROM `test` WHERE `user`=\"".$_POST["user"]."\"","num_rows");
if (strlen(trim($_POST["user"])) < 3 || $usrindb > 0){
$fehlerfrei = FALSE;
$fehleruser = TRUE;
}
Das Scriopt läuft bis zur Stelle der Userabfrage aus der DB. Da kommt dann die Fehlermeldung!