Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Błąd wprowadzenia danych do bazy
-Laran-
post
Post #1





Goście







Witam.

Problem polega na tym że staram się wprowadzić dane do bazy przez PHP i nie mogę tego zrobić. Gdzie leży błąd?

  1. <?php
  2. require_once("connection.php");
  3.  
  4. if(!empty($_POST)){
  5. $indexTitle = $_POST["tytul"];
  6. $indexContent = $_POST["tresc"];
  7.  
  8. $adminIndexValues = "INSERT INTO `vm_index` VALUES('$indexTitle','$indexContent',now())";
  9. $adminIndex = mysql_query($adminIndexValues);
  10.  
  11. if(!$adminIndex) {
  12. echo "Błąd<br>";
  13. }
  14. if(empty($_POST["tytul"])) {
  15. echo "Brak tytułu<br>";
  16. }
  17. if(empty($_POST["tresc"])) {
  18. echo "Brak tresci<br>";
  19. }
  20. }
  21. ?>
  22.  
  23. <div id="regbox">
  24. <form action="admin_index.php" method="POST">
  25. <p>
  26. <label>Tytuł:</label> <input type="text" id="tytul" name="tytul" />
  27. </p>
  28. <p>
  29. <label>Treść:</label> <textarea id="tresc" name="tresc" rows="20" cols="50"></textarea>
  30. </p>
  31. <input type="submit" value="Dodaj">
  32. </form>
  33. </div>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
-Laran-
post
Post #2





Goście







Sorry za problem, ale CMS na którym pracuje (UserCake) inaczej łączy się z bazą danych i nie sprawdziłem tego.

  1. $db_host = "localhost";
  2. $db_name = "name";
  3. $db_user = "user";
  4. $db_pass = "pass";
  5. $db_table_prefix = "prefix_";
  6.  
  7. $mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
  8. GLOBAL $mysqli;


Tak wygląda plik po zmianach (działa już):
  1. if(!empty($_POST)){
  2. $indexTitle = $_POST["tytul"];
  3. $indexContent = $_POST["tresc"];
  4.  
  5. $stmt = $mysqli->prepare("INSERT INTO vm_index (tytul,tresc,data) VALUES ($indexTitle,$indexContent,now())");
  6. $stmt->bind_param("s", $indexTitle, $indexContent);
  7. $stmt->execute();
  8. $stmt->close();
  9.  
  10. if(empty($_POST["tytul"])) {
  11. echo "Błąd tytułu<br>";
  12. }
  13. if(empty($_POST["tresc"])) {
  14. echo "Błąd tresci<br>";
  15. }
  16. }
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 28.12.2025 - 18:48