Ertekek beszurasa adatbazisba
<?php
if(isset($_POST['submit']))
{
$users = explode(",", $_POST['name']);
$find = mysql_query("SELECT user_id, username FROM register WHERE username IN('". implode ("', '", $users) ."')");
mysql_query("INSERT INTO messages (id, subiect, message, send_date) VALUES (0, '".$_POST['subiect']."', '".$_POST['mesaj']."', NOW())");
$messages_id = mysql_insert_id();
while ($row = mysql_fetch_array($find))
{
mysql_query("INSERT INTO pm (id, msg_id, fromuserid, fromusername, touserid, folderid, messageread) VALUES (0, '".$messages_id."', '".$_SESSION['uid']."', '".$_SESSION['username']."', '".$row['user_id']."', '0', 'no')") or die(mysql_error());
$pm_id = mysql_insert_id();
if (isset($_FILES['file']['tmp_name']) && $_FILES['file']['tmp_name'])
{
foreach ($_FILES["file"]["name"] as $key => $name)
{
$rand = substr(md5( time() . $_FILES['file']['name'][$key]), 0, 15);
$target = "/home2/devfirst/files/";
$target = $target . $rand;
if(move_uploaded_file($_FILES['file']['tmp_name'][$key], $target))
{
mysql_query("INSERT INTO files (id, name, newname, size, type) VALUES (0, '".$_FILES['file']['name'][$key]."', '".$rand."', '".$_FILES['file']['size'][$key]."', '".$_FILES['fisier']['type'][$key]."')") or die(mysql_error());
print mysql_insert_id();
}
}
mysql_query("INSERT INTO files_parent (id, pmid, filesid, fromuserid) VALUES (0, '".$pm_id."', '".$files_id."', '".$_SESSION['uid']."')") or die(mysql_error());
}
}
}
?>
Veszi a messages tabla azonositojat (ID) es beszurja egy masik tablaba pm annyi usernek ahanynak az uzenett kuldve lett.
Ha az uzenethez fajlot csatolok, ezeket a fajlokat beirja egy files nevu tablaba.
Van egy masik tabla is files_parent ahol megadom melyik sor a pm tablabol melyik fajlot kapta.
files_parent
id | pmid | filesid | fromuserid
====================================
id | pmid | filesid | fromuserid
====================================
1 | 1 | 1 |
2 | 1 | 2 |
3 | 2 | 1 |
4 | 2 | 2 |
Tudna valaki segiteni ? Koszonom !