Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z zapytaniem INSERT INTO
Forum PHP.pl > Forum > Bazy danych > MySQL
bezimienny
Witam...
Mam problem z zapytaniem do mojej bazy.
Oto wiadomość zwracana przez serwer...
  1. You have an error IN your SQL syntax; CHECK the manual that corresponds TO your MySQL server version FOR the RIGHT syntax TO USE near 'check,day,month,year,date,time_h,title,time_end,time_min) VALUES ('7','asdf','fe' at line 1

Sama kwerenda działa dobrze, bo próbowałem na innym przykładzie... Tylko w tym właśnie mam problemy. Próbowałem różne metody.

A oto kod php:
  1. <?php
  2. action::add('cal',array($_POST['id'],$_POST['entry'],$_POST['kind'],$_POST['check'],$_POST['day'],$_POST['month'],$_POST['year'],$_POST['date'],$_POST['time_h'],$_POST['title'],$_POST['time_e_h'].":".$_POST['time_e_m'],$_POST['time_min'])); break;
  3. ?>

Metoda action działa dobrze.
  1. <table class=con>
  2. <form action="index.php?s=6&where=cal&act=add" method="post">
  3. <input type="hidden" name="where" value="cal">
  4. <input type="hidden" name="id" value="<? echo action::maxi('cal'); ?>">
  5. <input type="hidden" name="day" value="<? print($_GET['day']); ?>">
  6. <input type="hidden" name="month" value="<? print($_GET['month']); ?>">
  7. <input type="hidden" name="year" value="<? print($_GET['year']); ?>">
  8. <input type="hidden" name="date" value="<? print($_GET['year']."-".$_GET['month']."-".$_GET['day']); ?>">
  9. <input type="hidden" name="check" value="0">
  10. <tr><td class=form>Data:</td><td class=form width="70px"><? print($_GET['day']."-".$_GET['month']."-".$_GET['year']); ?></td><td>
  11. <select name="kind" value="">
  12. <option value ="all">Ogólny</option>
  13. <option value="sth">Cos</option>
  14. </select>
  15.  
  16. </td></tr>
  17. <tr><td class=form>Czas:</td><td class=form width=80px>Start <input size=2 class=con type="text" name="time_h" value="">:<input size=2 class=con type="text" name="time_min"></td><td class=form>Koniec: <input size=2 class=con type="text" name="time_e_h" value="">:<input size=2 class=con type="text"" name="time_e_m" value=""></td></tr>
  18. <tr><td class=form>Tytuł: </td><td class=con colspan="2"><input size=59 class=con type="text" name="title" value=""></td></tr>
  19. <tr><td class=form>Text: </td><td class=con colspan="2"><textarea class=con name="entry" cols="57" rows="6"></textarea>
  20. </td></tr>
  21. <tr><td class=submit colspan="3"><input type="submit" value="<? echo lang::sh_lang('en_lang','save'); ?>">
  22. <input type="reset" value="<? echo lang::sh_lang('en_lang','reset'); ?>"></td></tr></table>

help please!
yalus
to podeslij kod mysql
wojckr
Jeśli np. w $_POST['cos'] bedzie pusto, a kolumna w tabeli nie dopuszcza NULL, to może być problem (to tak ogólnie).
yalus
tak, tylko to by bylo info o null a nie syntax error

cos w samym zapisie mysql jest nie tak

widzisz dla jednych danych ci przechodzi a dla innych nie

podeslij cale zapytanie mysql jakiego uzywasz
_bezimienny
  1. $string1 = implode("','",$list); // pobrana tablica
  2. $this->result = mysql_query("SHOW COLUMNS FROM ".$table); IF (mysql_num_rows($this->result) > 0)
  3. {
  4. $i=0;
  5. while ($row = mysql_fetch_assoc($this->result))
  6. {
  7. $label[$i] = $row[FIELD];
  8. $i++;
  9. }
  10. }
  11. $labels = implode(",",$label);
  12. $this->result = mysql_query("INSERT INTO ".$table." (".$labels.") VALUES ('".$string1."')",$this->connect) OR die("The entry cannot be added!<br>".mysql_error());
  13. echo "The entry was added <br>";

Takie o to coś.
Z NULL to nie ma związku...

@yalus, masz jakiś pomysł?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.