Jump to content
php.lv forumi

kā piesaistīt pie lietotāja


ziedinjsh

Recommended Posts

šāds ir upload kods:

 

if (isset($_POST['get_photo'])) {

// faila detaljas
$p_name = $_FILES["photo"]["name"];
$p_type = $_FILES["photo"]["type"];
$p_size = $_FILES["photo"]["size"];
$p_temp = $_FILES["photo"]["tmp_name"];
$p_error = $_FILES["photo"]["error"];
$p_date = date("Y-m-d");


if($p_error > 0)
  die ("photo culd not uploaded! Code: $p_error");

 else {

 //Faila nosaciijumi
   if($p_type == "application/octet-stream" || $p_size >3145728) {
 die("this format is not allowed or file is to big");

 }
 else
 {

$query = mysql_query("INSERT INTO photos (p_name, p_type, p_size, p_date) VALUES ('$p_name','$p_type','$p_size','$p_date') ");
 move_uploaded_file($p_temp,"uploads/".$p_name);
  echo "photo uploaded!";
  }
}	




}
echo "<form method='post' action='".$_SERVER['PHP_SELF']."' enctype='multipart/form-data'>";
echo "<input type='file' name='photo'>";
echo "<input type='submit' value='Upload' name='get_photo'>";
echo "</form>";

 

kā es varu piesaistīt augšupielādējamo bildi pie tā usera kas viņu augšupielādē

 

useri atpazēst šādi:

$result = mysql_query("SELECT * FROM users WHERE ID = '{$_SESSION['user_ID']}'");

Link to comment
Share on other sites

nu tātad.. iekš photos izvdeoju user_id

 

uztaisīju šādi:

 

$user_id = $_SESSION['user_ID'];

 

ievada datubāzē šādi:

$query = mysql_query("INSERT INTO photos (p_name, user_id, p_type, p_size, p_date) VALUES ('$p_name', '$user_id', '$p_type','$p_size','$p_date') ");

 

bilde augšupielādējas visi dati tiek ievadīti, bet user_id neievada. Kapēc tā?

Link to comment
Share on other sites

tagad iet.. tagad sāku domāt kā tagad sanāk..

 

atverot profilu parādās username un email.. kā tagad izvadu bildi to kas katram ir

 

users.php man izvada šādi

 

$result = mysql_query("SELECT * FROM users ORDER BY id DESC");

 

bet kā lai uztaisa lai izvadītu arī informāciju no

$result = mysql_query("SELECT * FROM photos ");

 

???

Edited by ziedinjsh
Link to comment
Share on other sites

jā es esmu, bet kad man atrodas divi SELECT * FROM vienā lapā tad man vai nu viens vai otrs neiet.. nelasa infomāciju!

 

cik sakarīgs ir šāds variants?

$result = mysql_query("SELECT * FROM users, photos ORDER BY id DESC");

Edited by ziedinjsh
Link to comment
Share on other sites

Tad meklē kļūdu kādēļ neiet nevis domā jocīgus risinājumus - vaina noteikti ir tavā kodā.

 

Un tavs variants ir nesakarīgs.

 

Tu vari JOIN`ot tabulas kopā:

SELECT users.*, photos.* FROM users INNER JOIN photos ON users.id = photos.user_id WHERE photos.user_id = $id

 

Protams viņu vajag pieslīpēt tavām vajadzībām.

Link to comment
Share on other sites

nu jā..

 

<?php
include "misc/config.php";
include "header.php";
include "left.php";





$result = mysql_query("SELECT users.*, photos.* FROM users INNER JOIN photos ON users.id = photos.user_id WHERE photos.user_id = id ORDER BY id DESC");




if (isset($_POST['yes'])) {
mysql_query("UPDATE users SET yes = yes +1 WHERE id='id'");
}
elseif (isset($_POST['no'])) {
mysql_query("UPDATE users SET no = no +1 WHERE id='id'");
}




while($data = mysql_fetch_array($result))
{






echo "<table><tr>";
echo "<td>username</td><td>".$data['username']."</td>";
echo "</tr><tr>";
echo "<td>email</td><td>".$data['email']."</td>";
echo "</tr><tr>";
echo "<td>bilde</td><td><img src='photos/big/".$data['p_name']."' width='100'></td>";
echo "</tr><tr>";
echo "<td>do you like?</td><td>";
echo "<form method='post'><input type='submit' name='yes' value='yes' /></form>";
echo "<form method='post'><input type='submit' name='no' value='no' /></form>";
echo "</td>";


echo "</tr></table>";



echo "<hr>";

}


include "footer.php";
?>

 

no visiem lietotājiem man rādās tikai viens

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...