Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Newsy, Mam problem...
tommy4
post
Post #1





Grupa: Zarejestrowani
Postów: 288
Pomógł: 12
Dołączył: 2.12.2005

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


Wyobraźcie sobie tabelę:

id smallint(5) unsigned not null auto_increment
temat varchar(200) not null
autor smallint(5) unsigned not null default '1'
miesiac smallint(5) unsigned not null default '0'
tresc text not null
data int(10) unsigned not null default '0'

I mam taki problem: chcę dodać do bazy danych tylko i wyłącznie treść newsa i używam w tym celu takiego kodu:

  1. <?php
  2. require_once "../main.php";
  3. ?>
  4. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  5. <label>Treść:<br>
  6. <textarea name="tresc" rows="10" cols="40">
  7. </textarea></label><br>
  8. <input type="submit" value="Zapisz">
  9. </form>
  10.  
  11. <?php
  12. if (isset($_POST['tresc'])) {
  13. $trescnewsa = $_POST['tresc'];
  14. $sql = "INSERT INTO newsy (tresc) VALUES ('$trescnewsa')";
  15. if(@mysql_query($sql)) {
  16. echo '<p>Twój news został dodany.</p>';
  17. }
  18. else {
  19. echo '<p>Błąd podczas dodawania newsa: ' . mysql_error() . '</p>';
  20. }
  21. }
  22. ?>

(IMG:http://forum.php.pl/uwaga.gif)
poprawiam
---
nospor



Mam problem, nie chce się tabela dodawać. Wyświetla Bład podczas dodawania newsa. Co mam źle?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
banpl
post
Post #2





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 2.11.2005
Skąd: Radomsko

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


zrob tak w zapytaniu:

  1. <?php
  2.  
  3.  
  4. $sql = "INSERT INTO newsy (id, temat, autor, miesiac, tresc, data) VALUES ('', '', '', '', '$trescnewsa', '')";
  5.  
  6.  
  7. ?>


powinno dzialac (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
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: 5.10.2025 - 16:48