Jackal Posted March 11, 2006 Report Share Posted March 11, 2006 Kāpēc man neieposto datumu un laiku rāda: Notice: Undefined variable: laiks in c:\web page\easyphp\www\index.php on line 21 Un shitā ir tā 21 rinda: mysql_query("insert into koment(laiks,datums,vards,komente) values ('".$laiks."','".$datums."','".$vards."','".$koments."')") or die ("Neiet!"); Kas varētu būt pa vainu? Un reku viss skripts palabojiet lūdzu: <? function connect(){ $savienojums=mysql_connect("localhost","root","") or die ("Nav savienojuma ar serveri!"); mysql_select_db("database",$savienojums) or die ("Nevar savienoties ar DB!"); } echo "<body bgcolor='white' >"; connect(); if(isset($_POST['vards'])){$vards=htmlspecialchars($_POST['vards']);} else {$vards="";} if(isset($_POST['koments'])){$koments=htmlspecialchars($_POST['koments']);} else {$koments="";} if(isset($_POST['poga'])){ if($koments!=""){ if($vards=="")$vards="Anonîms"; mysql_query("insert into koment(laiks,datums,vards,komente) values ('$laiks','$datums','$vards','$koments')") or die ("Neiet!"); }else{ echo "<font color='red'>Ievadiet komentâru!</font>\n"; } } $kom=mysql_query("select * from `koment` order by `datums`,`laiks`"); if(mysql_numrows($kom)==0)echo "Komentâru ðeit paðlaik nav!"; echo "<ol>"; while($row=mysql_fetch_array($kom)){ $laiks=$row['laiks']; $vards=$row['vards']; $kome=$row['komente']; $datums=$row['datums']; echo "<li><p style='MARGIN-TOP: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0px; COLOR: #000000; PADDING-TOP: 0px; BORDER-BOTTOM: #ccc 0px; BACKGROUND-COLOR: #fcfcff; TEXT-ALIGN: left'>\n"; echo $kome; echo "</p><p style='BORDER-TOP: #ccc 1px dashed; MARGIN-TOP: 0px; PADDING-LEFT: 5px; MARGIN-BOTTOM: 10px; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0px; COLOR: #494949; PADDING-TOP: 0px; BORDER-BOTTOM: #ccc 1px dashed; BACKGROUND-COLOR: #ece8d9; TEXT-ALIGN: left'>\n"; echo $vards; echo " (ievietots "; echo $laiks." ".$datums; echo ")"; echo "</p></li>\n"; } echo "</ol>"; mysql_close(); $laiks=date("H:i:s"); $datums=date("Y-m-d"); ?> <br><br><br> <p> <form name="forma" method="POST" action="index.php?lapa=forums"> Laiks: <?php echo $laiks; ?> <br> Vârds:<br><input type="text" align="center" name="vards" size="22"><br> Komentârs:<br> <textarea rows="7" name="koments" align="center" cols="24"></textarea><br> <input type="submit" align="center" value="Nosûtît" name="poga"></p> </form> Lūdzu lieto BBtagus (bubu) Link to comment Share on other sites More sharing options...
v3rb0 Posted March 11, 2006 Report Share Posted March 11, 2006 register_globals = Off Link to comment Share on other sites More sharing options...
Jackal Posted March 11, 2006 Author Report Share Posted March 11, 2006 ir jau off, bet neiepostojas Link to comment Share on other sites More sharing options...
bubu Posted March 11, 2006 Report Share Posted March 11, 2006 Tak tur jau tā lieta, ka ir off! Ja būtu on, tad nebūtu kļūdas. Taču neiesaku likt uz on. Labāk salabo kodu, lai strādā uz off. Link to comment Share on other sites More sharing options...
Jackal Posted March 11, 2006 Author Report Share Posted March 11, 2006 (edited) Es nomainiju register globals=on, bet tagad man parāda erroru 23 rindā un tāpat laiks un datums neiepostojas Edited March 11, 2006 by Jackal Link to comment Share on other sites More sharing options...
bubu Posted March 11, 2006 Report Share Posted March 11, 2006 Mums jāzīlē savās kristāla bumbās kādu erroru tev rāda?!? Link to comment Share on other sites More sharing options...
Jackal Posted March 11, 2006 Author Report Share Posted March 11, 2006 Notice: Undefined variable: laiks in c:\web page\easyphp\www\index.php on line 23 Link to comment Share on other sites More sharing options...
SkyD Posted March 11, 2006 Report Share Posted March 11, 2006 (edited) Nodefinē mainīgos $laiks un $datums. $laiks = date('H:i:s'); $datums = date('d.m.y'); edit: Baigi neparocīgi tu visu tur esi sarakstījis. No sākuma pārbaudi vai tukši lauki, tad raksti iekšā. Es daru tā: if (empty($_POST['vards'])) { $vards = 'Anonīms'; } $bla = date('H:i:s'); $spiezham = mysql_query("INSERT INTO komenti (bla,bla,bla) VALUES('$bla', '$bla', '$bla')"); Edited March 11, 2006 by SkyD Link to comment Share on other sites More sharing options...
Jackal Posted March 11, 2006 Author Report Share Posted March 11, 2006 (edited) Nu es esmu iesācējs ar php un nemāku nodefinēt, kas tur ir jāpiraksta klāt? Edited March 11, 2006 by Jackal Link to comment Share on other sites More sharing options...
SkyD Posted March 11, 2006 Report Share Posted March 11, 2006 Es tev jau parādīju, kas jadara. Šitos: $laiks = date('H:i:s'); $datums = date('d.m.y'); Ieliec pirms mysql_query, kur tu raksti iekshaa.. Link to comment Share on other sites More sharing options...
Recommended Posts