Witam!
Jestem w końcowej fazie przygotowań nowego "działu" na stronie i stanąłem w miejscu, jeśli chodzi o formularz.
Po wypełnieniu formularza nie jest sprawdzana poprawność "wymaganych" pól ani dane z tego formularza nie są przesyłane do bazy...
Struktura tabeli
wierszeid, tytul, text, oryg_autor, nick, date, stat, opened, vcount, vvalue
Poniżej przedstawiam co "zrobiłem"...
<? include('config.php');
function site_main() {
global $id, $cmd, $down_limit, $mess, $nick, $avatar;
switch($cmd) {
case 'dodaj':
echo '<table width=100% border=0 align=center vAlign=top><tr><td>'; main_text_open();
<table width=99% align=center vAlign=top border=0>
<tr>
<td valign=top>
<font face=verdana size=1><a href="login.php">Pełny dostęp do działu mają osoby zalogowane.<br><a href="http://www.next.masternet.pl/login.php" title="logowanie"><u>Zaloguj się</u></a>.<br><br>Nie masz konta?<br><a href="http://www.next.masternet.pl/login.php?cmd=#reg" title="rejestracja"><u>Zarejestruj się!</u></a>.</a></font>
</td>
</tr>
</table>';
formularz();
//losowanie hasła z obrazka
for($i=0;$i<5;$i++) {
if (eregi("[0-9a-zA-Z]",$znak)) $haslo .= $znak; else $i--;
}
$_SESSION["kod"] = $haslo;
main_text_close();
echo '</td></tr></table>'; //}
break;
case 'dodaj_wiersz':
main_title_open();
echo '<center>dodaj_wiersz</center>'; main_title_close();
main_text_open();
check_form();
//list_fsearch_data();
main_text_close();
break;
#=====================================================#
.
.
.
#=====================================================#
function formularz() {
global $wiersze_tbl, $nick, $tytul, $text, $zalogowany;
$info = get_user_info();
<form name="wiersze" method="post" enctype="multipart/form-data">
<table border="0" cellspacing="3" cellpadding="0">
<tr>
<td align="right" class="uni_01">Twój nick:</td>
<td class="uni_01"><b>'.$info[1].'</b><input type="hidden" name="nick" value="'.$info[1].'">
</td>
</tr>
<tr>
<td align="right" class="uni_01">Autor(*):</td>
<td class="uni_01"><input type="text" name="autor" size="60" value="">
</td>
</tr>
<tr>
<td align="right" class="uni_01">Tytuł:</td>
<td><input type="text" name="tytul" size="60"></td>
</tr>
<tr>
<tr>
<td align="right" class="uni_01">Treść wiersza:</td><td class="uni_01">
<textarea cols="60" rows="20" type="text" name="text" value=""></textarea>
</td>
</tr>
<tr>
<td class="uni_01" valign="top"><div align="right">Weryfikacja(**):</div></td>
<td class="uni_01"><img src="obrazek.php"> <input type="text" name="weryfikacja">
</td>
</tr>
<td align="right" class="uni_01"> </td>
<td class="uni_01"><input style="font-weight: bold;" type="submit" name="ok" value="OK">
<input type="reset" name="reset" value="Wyczyść pola">
<input type="hidden" name="cmd" value="dodaj_wiersz"></td>
</tr>
</table>
</form>';
}
#=====================================================#
.
.
.
#=====================================================#
function check_form() {
global $tytul, $text, $oryg_autor, $nick; if(check_form_data()<>10) {
} else {
$query = "INSERT INTO wiersze VALUES (NULL, '$tytul', '$text', '$oryg_autor', '$nick', now(), '0', '0', 0, '0.00')";
if($result) {
echo 'Wiersz zostal dodany.'; echo '<br><br><center>[<a href="index.php">strona główna</a>]</center><br>';
} else {
echo 'Baza danych chwilowo niedostepna. Odczekaj kilka minut i spróbuj dodać wiersz po
nownie.<br>Jeżeli problem będzie się powtarzał zawiadom o tym <a href="mailer.php">admina</a>';
}
}
}
#=====================================================#
function check_form_data() {
$nick = $_GET['nick'];
if (strtolower($_POST["weryfikacja"])<>strtolower
($_SESSION["kod"]) and
isset($_POST["weryfikacja"])) $a++; {}
if($tytul=='') $err[0] = 1;
if($text=='') $err[1] = 1;
if($nick=='') $err[2] = 1;
//$text_l = strlen($text);
//if($text_l>200) $err[3] = 1;
//if(!ereg ("^.+@.+..+$", $mail)) $err[4] = 1;
$error = 0;
if($err[0]==1) {
echo '<br>Nie wprowadzono tytulu. '; $error++;
}
if($err[1]==1) {
echo '<br>Nie wprowadzono tresci wiersza. '; $error++;
}
if($err[2]==1) {
echo '<br>Nie podano autora. '; $error++;
}
if($err[3]==1) {
$error++;
}
if($err[4]==1) {
$error++;
}
if($error<>0
) echo '<br><br><center>[<a href="javascript:history.back();">wstecz</a>]</center><br>';
if($error==0) return 10;
}
#=====================================================#
$site_title = tytul_wiersze();
$meta_info = '';
include("theme/$theme/normal.php");
?>
W pliku zostawiłem tylko te funkcje, które są potrzebne do formularza - inaczej byłby to bardzo długi plik...
Czy ktoś z Was byłby w stanie sprawdzić powyższy plik i napisać, w którym miejscu (lub w których miejscach) robię błąd (błędy)?
Bardzo proszę o jakąkolwiek odpowiedź...
Ten post edytował roobik 27.01.2008, 10:25:01