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;}
?>
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;
?>
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;
?>