Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Updateowanie rekordu w bazie
imlegend
post 29.01.2014, 10:43:46
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 22.12.2012

Ostrzeżenie: (0%)
-----


Witam , mam skrypt zapisujący zdjęcia na serwer, a info do bazy.
Chodzi mi o fragment tego skryptu odpowiadający za update rekordu w bazie.
Nie wiem jak powiązać wstawiane dane z id. Mianowicie gdy wstawiam wartość id = 1 - zapisuje bez problemu,
ale gdy daje "where id = $id" wtedy nic się nie dzieje. Chodzi o to żeby rekord był zupdatowany dla użytkownika o określonym id.


  1.  
  2.  
  3. //This is the directory where images will be saved
  4. $target = "wyslane/";
  5. $target = $target . basename( $_FILES['photo']['name']);
  6.  
  7. //This gets all the other information from the form
  8. $id =$_POST['id'];
  9. $name=$_POST['name'];
  10.  
  11. $pic=($_FILES['photo']['name']);
  12.  
  13. // Connects to your Database
  14. mysql_connect("x", "x", "x") or die(mysql_error()) ;
  15.  
  16. //Writes the information to the database
  17. //mysql_query("INSERT INTO `employees` VALUES ('$name', '$pic')") ;
  18.  
  19.  
  20.  
  21. mysql_query("UPDATE users SET name='$name', photo='$pic' WHERE id = $id");
  22.  
  23. //Writes the photo to the server
  24. if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
  25. {
  26.  
  27. //Tells you if its all ok
  28. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
  29.  
  30. }
  31. else {
  32.  
  33. //Gives and error if its not
  34. echo "Sorry, there was a problem uploading your file.";
  35. }
  36.  
  37.  
  38.  
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.07.2025 - 21:53