Advertisement
Guest User

Mein Code

a guest
Sep 5th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.28 KB | None | 0 0
  1. DB Connection:
  2.  
  3. <?php
  4. function connect(){
  5.         session_start();
  6.         $server = "host";
  7.         $benutzer = "Benutzer";
  8.         $pass = "pass";
  9.         $_SESSION['tabelle'] = "tabelle";
  10.         $conn = mysqli_connect($server, $benutzer, $pass, $_SESSION['tabelle']);
  11. return $conn;
  12. }
  13. function getAllUsers($conn){
  14.         $sql = "SELECT * FROM `users`";
  15.        
  16.         $dbResult = mysqli_query($conn, $sql);
  17.         $userArry = array();
  18.         while($row = mysqli_fetch_array($dbResult)){
  19.                 $user = array();
  20.                 $user['userName'] = $row['userName'];
  21.                 $user['userPassword'] = $row['userPassword'];
  22.                 $user['userID'] = $row['userID'];
  23.                 $userArry[] = $user;
  24.         }
  25.         return $userArry;
  26. }
  27.  
  28. function getUser($conn, $userId){
  29.         $sql = "SELECT * FROM `users` WHERE `userID` = ".mysqli_real_escape_string($conn, $userId);
  30.        
  31.         $dbResult = mysqli_query($conn, $sql);
  32.         while($row = mysqli_fetch_array($dbResult)){
  33.                 $user = array();
  34.                 $user['userName'] = $row['userName'];
  35.                 $user['userPassword'] = $row['userPassword'];
  36.                 $user['userID'] = $row['userID'];
  37.                 return $user;
  38.         }
  39.        
  40.         return NULL;
  41. }
  42. ?>
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. Mein Code der den Error Ausgibt:
  50.  
  51. <?php
  52. include("helper.php");
  53. $database = connect();
  54. $user = getAllUsers($database);
  55.            
  56.             $sql = "SELECT * FROM ".$_SESSION['klasse']."";
  57.             $dbResult = mysqli_query($database, $sql);
  58.             while($row = mysqli_fetch_array($dbResult)){
  59.                 $chatEntry = array();
  60.                 $chatEntry['userID'] = $row['userID'];
  61.                 $chatEntry['userText'] = $row['text'];
  62.                 $chatEntry['Time'] = $row['time'];
  63.                 $user = getUser($database, $chatEntry['userID']);
  64.                 $chatText = strip_tags($chatEntry['userText'], '<a></a><img>');
  65.                 $urlsuch[]="/([^]_a-z0-9-=\"'\/])((https?|ftp):\/\/|www\.)([^ \r\n\(\)\^\$!`\"'\|\[\]\{\}<>]*)/si";
  66.                 $urlsuch[]="/^((https?|ftp):\/\/|www\.)([^ \r\n\(\)\^\$!`\"'\|\[\]\{\}<>]*)/si";
  67.                 $urlreplace[]="\\1[URL]\\2\\4[/URL]";
  68.                 $urlreplace[]="[URL]\\1\\3[/URL]";
  69.                 $chatText = preg_replace($urlsuch, $urlreplace, $chatText);
  70.                 $chatText = preg_replace("/\[URL\]www.(.*?)\[\/URL\]/si", "<a target=\"_blank\" href=\"http://www.\\1\">www.\\1</a>", $chatText);
  71.                 $chatText = preg_replace("/\[URL\](.*?)\[\/URL\]/si", "<a target=\"_blank\" href=\"\\1\">\\1</a>", $chatText);
  72.                 $chatText = preg_replace("/(http:\/\/)?(.*\.(de|com|at|net)[^\s]*)/","<a target='_blank' href='http:\/\/$2'>$2</a>", $chatText);
  73.                 $chatText = preg_replace("/(:D)/","<img src='img/smilie1.png' style='height:20px; width:20px;'>", $chatText);
  74.                 $chatText = preg_replace("/(:\()/","<img src='img/smilie2.png' style='height:20px; width:20px;'>", $chatText);
  75.                 $chatText = preg_replace("/(\(creeper\))/","<img src='img/smilie3.png' style='height:20px; width:20px;'>", $chatText);
  76.                 $chatText = preg_replace("/(\;\))/","<img src='img/smilie4.png' style='height:20px; width:20px;'>", $chatText);
  77.                 $chatText = preg_replace("/(\(fu)\)/","<img src='img/smilie5.png' style='height:20px; width:22px;'>", $chatText);
  78.                 echo $user['userName'] . ": <lable style='color:#D8D8D8'>" . $chatText . " </lable>~" . $chatEntry['Time'] . "~";
  79.                 echo "<br>";
  80.             }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement