Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
Ime slike, upis u bazu

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side
View previous topic :: View next topic  
Author Message
Hrvoje



Joined: 03 Sep 2004
Posts: 132
Location: My office

PostPosted: 28.01.2010 23:24    Post subject: Ime slike, upis u bazu Add user to your forum ignore list Reply with quote

Imam skriptu koja mi dodaje naslov, tekst i datum u bazu, a sliku uploada u folder upload.
Skripta mi radi sve ok osim sto nece da mi upiše ime slike u polje od baze, u polju mi piše Array umjesto imena slike.



Code:
<?php

include "spoj.php";


if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("images/upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "images/upload/" . $_FILES["file"]["name"];
    
    
     $datum=date("Y-m-d");

$sql="INSERT INTO novosti (naslov, tekst, datum, slika)

VALUES ('$_POST[naslov]', '$_POST[tekst]', '$datum', '$_FILES')";

if (mysql_query($sql))

{

echo "Novost je uspješno pohranjena";

} else {

echo "Nastala je greška pri pohrani novosti<br>" . mysql_error();

}
    
    
      }
    }
  }
else
  {
  echo "Invalid file";
  }
 
 
?>
Back to top
View user's profile Send private message
srle



Joined: 05 Jan 2006
Posts: 5
Location: Čakovec

PostPosted: 29.01.2010 09:39    Post subject: Re: Ime slike, upis u bazu Add user to your forum ignore list Reply with quote

echo "Upload: " . $_FILES["file"]["name"] . "<br />";
pa ispisujes ime slike,

znaci treba biti
sql="INSERT INTO novosti (naslov, tekst, datum, slika)

VALUES ('$_POST[naslov]', '$_POST[tekst]', '$datum', '$_FILES["file"]["name"]'')";

$_FILES ti je array sa svim slikama, jer u formi mozes imati vise slika
Back to top
View user's profile Send private message Visit poster's website
Hrvoje



Joined: 03 Sep 2004
Posts: 132
Location: My office

PostPosted: 29.01.2010 19:54    Post subject: Add user to your forum ignore list Reply with quote

Jesam probao sam vec, ali mi javi u tom redu:

Code:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'
Back to top
View user's profile Send private message
strija



Joined: 14 Sep 2003
Posts: 473
Location: Čakovec

PostPosted: 29.01.2010 21:08    Post subject: Add user to your forum ignore list Reply with quote

Moras paziti na navodnike, ne samo copy/paste:
Code:
$sql = "INSERT INTO novosti (naslov, tekst, datum, slika)
VALUES ('".$_POST['naslov']."', '".$_POST['tekst']."', '".$datum."', '".$_FILES['file']['name']."')";


Mozda da koristis prepared statements, pa ti budem pregledniji kod, a i nije lose radi securitya Wink

_________________
We can exist in ambiguity, but it means the deepest loneliness. | creolab.hr | thefarewellreason.com
Back to top
View user's profile Send private message Visit poster's website
Hrvoje



Joined: 03 Sep 2004
Posts: 132
Location: My office

PostPosted: 31.01.2010 21:00    Post subject: Add user to your forum ignore list Reply with quote

Hvala Laughing radi Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Server-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group