PM in loginsystem

Uemit

Mitglied
hi leute ich hab ne problem ich hab ne login script mit DW erstellt und habe ein bereich Private message erstellt wo die user sich gegen einander nachrichten schreiben können sollen. aber ich habe ne problem ich hab ne formular erstellt wo die user die nachricht in datenbank einfügen können ich weis jetzt nicht wie ich es ausgeben kann ich habe in datenbank die zeilen

sender
target
nachricht
betreff
time
status

wie soll ich es wissen wem der user ein nachricht geschrieben hat.
hier das code:

pm.php
PHP:
<?php require_once('Tabelle.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO nachrichten (sender, target, nachricht) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['gönderen'], "text"),
                       GetSQLValueString($_POST['baslik'], "text"),
                       GetSQLValueString($_POST['mesaj'], "text"));

  mysql_select_db($database_Tabelle, $Tabelle);
  $Result1 = mysql_query($insertSQL, $Tabelle) or die(mysql_error());
}

mysql_select_db($database_Tabelle, $Tabelle);
$query_Recordset1 = "SELECT Nickiniz FROM uyeler";
$Recordset1 = mysql_query($query_Recordset1, $Tabelle) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="307" border="1">
    <tr>
      <td width="86"><div align="right"><strong>G&ouml;nderen:</strong></div></td>
      <td width="205"><input name="sender" type="text" id="g&ouml;nderen" value="<?php echo $row_Recordset1['Nickiniz']; ?>" size="34"> </td>
    </tr>
    <tr>
      <td><div align="right"><strong>Baslik:</strong></div></td>
      <td><input name="betreff" type="text" id="baslik2" size="34"></td>
    </tr>
    <tr>
      <td><div align="center"><strong>Mesajiniz:</strong>
      </div></td>
      <td><textarea name="nachricht" cols="30" rows="5" id="textarea2"></textarea></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
          <input type="submit" name="Submit" value="G&ouml;nder">
          <input type="submit" name="Submit2" value="Vazgec">
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>




<?php
mysql_free_result($Recordset1);
?>

user.php
PHP:
<?php require_once('Tabelle.php'); ?>
<?php
mysql_select_db($database_Tabelle, $Tabelle);s
?>
<?
$result=mysql_query("SELECT * from uyeler"); 
while ($row=mysql_fetch_array($result)){ 
$benutzerid=$row["id"]; 
$benutzername=$row["Nickiniz"]; 

echo  "<a href=pm.php?benutzerid=$benutzerid>$benutzername</a>"; 

} 
?>
wie soll ich das für bestimmt user ausgeben die nachricht zu ihn geschikt wurde?
 
Zuletzt bearbeitet:
Du hast ja sicher in der Session die ID oder den Usernamen des Users gespeichert der gerade angemeldet ist.
target wird dann wohl das Feld sein mit der ID oder dem Usernamen des Empfaengers, also kannst Du anhand der in der Session gespeicherten Daten mittels WHERE im SQL-Query die Ausgabe filtern.
Beispiel:
PHP:
$userid=$_SESSION["id"];
$messages=mysql_query("select * from messages where target='$userid'");
while ($message=mysql_fetch_assoc($messages))
 {
  //Ausgabe der jeweiligen Message
 }
 
ja ich danke dir. Du hast mir sicherlich geholfen ich werde etz mal versuchen ich hoffe mal das es geht;).
 
Zuletzt bearbeitet:
ja hallo nochmal ich hab ne problem ich habs lange probiert aber nicht geschaft. Ich weis net wie ich die userid in die "target" schiken kann? könnt ihr mal mir helfen?. Danke an allen
 
Ja ok dies ist die Formular die ich die Daten in die Datenbank schike

PHP:
<?php require_once('Tabelle.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "hata.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO nachrichten (sender, baslik, nachricht, target) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['gönderen'], "text"),
                       GetSQLValueString($_POST['baslik'], "text"),
                       GetSQLValueString($_POST['nachricht'], "text"));
  mysql_select_db($database_Tabelle, $Tabelle);
  $Result1 = mysql_query($insertSQL, $Tabelle) or die(mysql_error());
}

mysql_select_db($database_Tabelle, $Tabelle);
$query_Recordset1 = "SELECT * FROM uyeler where Nickiniz = '".$_SESSION['MM_Username']."'"; 
$Recordset1 = mysql_query($query_Recordset1, $Tabelle) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<style type="text/css">
<!--
.Stil1 {
	font-size: 12px;
	font-weight: bold;
}
.Stil2 {font-size: 14}
.Stil4 {font-size: 14; font-weight: bold; }
-->
</style>




<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="307" border="0">
    <tr>
      <td width="86"><div align="right" class="Stil1 Stil2">G&ouml;nderen:</div></td>
      <td width="205"><input name="g&ouml;nderen" type="text" id="g&ouml;nderen" value="<?php echo $row_Recordset1['Nickiniz']; ?>" size="34" readonly="true"></td>
    </tr>
    <tr>
      <td><div align="right" class="Stil4">Baslik:</div></td>
      <td><input name="baslik" type="text" id="baslik2" size="34"></td>
    </tr>
    <tr>
      <td><div align="right" class="Stil4">Mesajiniz:
      </div></td>
      <td><textarea name="mesaj" cols="30" rows="5" id="textarea2"></textarea></td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
          <input type="submit" name="Submit" value="G&ouml;nder">
          <input type="submit" name="Submit2" value="Vazgec">
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<?php
mysql_free_result($Recordset1);
?>
.

Und ich weis nicht wie ich die empfänger username in die "target" schicken soll. Ich warte dein Antwort.
 
Hier hast Du doch schon fast alles was Du brauchst:
PHP:
$insertSQL = sprintf("INSERT INTO nachrichten (sender, baslik, nachricht, target) VALUES (%s, %s, %s)", 
                       GetSQLValueString($_POST['gönderen'], "text"), 
                       GetSQLValueString($_POST['baslik'], "text"), 
                       GetSQLValueString($_POST['nachricht'], "text"));
Dort musst Du nur noch die Variable aus dem Formular anhaengen welche den Empfaenger enthaelt.
Also bei bei VALUES ein weiteres ,%s einfuegen und nach den 3 GetSQLValueString() das nochmal einfuegen mit der Variable fuer den Empfaenger.
 

Neue Beiträge

Zurück