![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 93 Pomógł: 5 Dołączył: 15.12.2007 Ostrzeżenie: (0%) ![]() ![]() |
Chcę umieścić w niektórych polach wartości Null. Oczywiście już uwzględniłem taką możliwość w bazie danych. Mam już działające rozwiązanie, ale mój aktualny kod jest bardzo długi:
CODE mysql_connect(localhost, xxxxx, xxxxxx) or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); mysql_query('SET CHARACTER SET utf8'); mysql_query('SET NAMES utf8'); $numer = NULL; $tytul = addslashes($_GET['tytul']);; $rodzaj = "Tipsy i kody"; $komputer = addslashes($_GET['komputer']); $tresc= addslashes($_GET['tresc']); $autor = addslashes($_GET['autor']); $zrodlo = addslashes($_GET['zrodlo']); if (empty($autor) && empty($zrodlo)) { $query = "INSERT INTO `wilq`.`tnt` ( `numer` , `tytul` , `tresc` , `rodzaj` , `komputer` , `autor` , `zrodlo`) VALUES ( '$numer' , '$tytul', '$tresc', '$rodzaj', '$komputer', null, null)"; $result = mysql_query($query); echo $query;} elseif (empty($autor)) { $query = "INSERT INTO `wilq`.`tnt` ( `numer` , `tytul` , `tresc` , `rodzaj` , `komputer` , `autor` , `zrodlo`) VALUES ( '$numer' , '$tytul', '$tresc', '$rodzaj', '$komputer', null, '$zrodlo')"; $result = mysql_query($query); echo $query;} elseif (empty($zrodlo)) { $query = "INSERT INTO `wilq`.`tnt` ( `numer` , `tytul` , `tresc` , `rodzaj` , `komputer` , `autor` , `zrodlo`) VALUES ( '$numer' , '$tytul', '$tresc', '$rodzaj', '$komputer', '$autor', null)"; $result = mysql_query($query); echo $query;} else { $query = "INSERT INTO `wilq`.`tnt` ( `numer` , `tytul` , `tresc` , `rodzaj` , `komputer` , `autor` , `zrodlo`) VALUES ( '$numer' , '$tytul', '$tresc', '$rodzaj', '$komputer', '$autor', '$zrodlo')"; $result = mysql_query($query); echo $query;} ?> Jak to skrócić? Próbowałem eksperymentować w tym kierunku, ale niestety nie do końca to działa. Dane są przekazywane, ale w bazie danych nie pojawiają się wartości null, a jedynie puste pola. Kod mysql_connect(localhost, xxxx, xxxxx) or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error()); mysql_query('SET CHARACTER SET utf8'); mysql_query('SET NAMES utf8'); $numer = NULL; $tytul = addslashes($_GET['tytul']);; $rodzaj = "Tipsy i kody"; $komputer = addslashes($_GET['komputer']); $tresc= addslashes($_GET['tresc']); $autor = addslashes($_GET['autor']); $zrodlo = addslashes($_GET['zrodlo']); if (empty($autor)) {$autor == 'null';} if (empty($zrodlo)) {$zrodlo == 'null';} $query = "INSERT INTO `wilq`.`tnt` ( `numer` , `tytul` , `tresc` , `rodzaj` , `komputer` , `autor` , `zrodlo` ) VALUES ( '$numer' , '$tytul', '$tresc', '$rodzaj', '$komputer', '$autor', '$zrodlo')"; $result = mysql_query($query); echo $query; ?> Ten post edytował charlie-cherry 26.01.2008, 07:27:34 |
|
|
![]() ![]() |
![]() |
Aktualny czas: 11.10.2025 - 21:39 |