Witam
Chciałem zrobić prosty system newsów, ale niestety mam problem. Otóż, chodzi o to, że wypełniam wszystkie pola, klikam dodaj, ale w bazie nic nowego się nie pojawia. Oto kod (wiem, że może być źle napisany, ale nie jestem geniuszem w tym temacie, inaczej nie wpisywałbym się w dziale przedszkole (IMG:
style_emoticons/default/smile.gif) ):
<?php
$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'pass';
if(! $conn )
{
}
$tytul=$_POST['tytul'];
$wstep=$_POST['wstep'];
$calosc=$_POST['calosc'];
$autor=$_POST['autor'];
if (empty($_POST['tytul']) || empty($_POST['wstep']) || empty($_POST['calosc']) || empty($_POST['autor'])) {
echo "<center><b>WYPEŁNIJ WSZYSTKIE POLA!</b></center><br />"; } else {
$sql = "INSERT INTO newsy ".
"(id,
tytul,
wstep,
calosc,
autor,
data) ".
"VALUES ".
"('',
'$tytul',
'$wstep',
'$calosc',
'$autor',
now())";
}
?>
I formularz:
<form method="post" action="<?php $_PHP_SELF ?>">
<table align="center" width="400" border="0" cellspacing="1" cellpadding="2"> <td width="100">Tytuł:
</td> <input name="tytul" type="text" id="tytul"> <td width="100">Wstęp:
</td> <td width="100">Cały tekst:
</td> <td width="100">Autor:
</td> <input name="autor" type="text" id="autor"> <input name="add" type="submit" id="add" value="Dodaj newsa">