monZy Posted April 11, 2005 Report Share Posted April 11, 2005 Testeju komentu sistemu vai vispar noalasa DB! Bet... <form action="index.php" method="post"> Niks: <input type="text" name="vards"><br> Mails: <input type="text" name="mails"><br> Webs: <input type="text" name="webs"><br> Komentars: <input type="text" name="koments"><br> <input type="Submit"> </form> <? $username="username"; $password="password"; $database="blog"; $vards=$_POST['vards']; $mails=$_POST['mails']; $webs=$_POST['webs']; $koments=$_POST['koments']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Sorry veciit nevaru piekonekteeties $database"); $query = "INSERT INTO komentari VALUES ('','$vards','$mails','$webs','$koments'')"; mysql_query($query); mysql_close(); ?> Kāds var pateikt kur šeit kļūda? Notice: Use of undefined constant localhost - assumed 'localhost' in c:\program files\apache group\apache\htdocs\tests\index.php on line 19 Itkā DB jau iet, phpMyAdmin parāda ir piekonektējas serverim, DB uzrāda, bet nezinu kur kļūda! Link to comment Share on other sites More sharing options...
Kavacky Posted April 11, 2005 Report Share Posted April 11, 2005 localhost -> 'localhost' Link to comment Share on other sites More sharing options...
monZy Posted April 11, 2005 Author Report Share Posted April 11, 2005 paldies , ieliku mazajas peediņās izdarīju 'localhost:3306' un aizgāja ;) paldies ;) Link to comment Share on other sites More sharing options...
bubu Posted April 11, 2005 Report Share Posted April 11, 2005 (edited) Notice: Use of undefined constant localhost - assumed 'localhost' in c:\program files\apache group\apache\htdocs\tests\index.php on line 19 Itkā DB jau iet, phpMyAdmin parāda ir piekonektējas serverim, DB uzrāda, bet nezinu kur kļūda! 16189[/snapback] Ievēro, ka tā nav kļūda (error), bet gan notice. Tāpēc jau arī viss strādā. Edited April 11, 2005 by bubu Link to comment Share on other sites More sharing options...
monZy Posted April 11, 2005 Author Report Share Posted April 11, 2005 Tagad taisu tālāk! index.php fails: <form action="index.php" method="post"> Niks: <input type="text" name="vards"><br> Mails: <input type="text" name="mails"><br> Webs: <input type="text" name="webs"><br> Komentars: <input type="text" name="koments"><br> <input type="Submit"> </form> <? $username="root"; $password="kaulac"; $database="blog"; $vards=$_POST['vards']; $mails=$_POST['mails']; $webs=$_POST['webs']; $koments=$_POST['koments']; mysql_connect('localhost:3306',$username,$password); @mysql_select_db($database) or die( "Sorry veciit nevaru piekonekteeties $database"); $query = "INSERT INTO komentari VALUES ('','$vards','$mails','$webs','$koments'')"; mysql_query($query); mysql_close(); include("kom.php") ?> un inkludotais kom.php <? $username="root"; $password="kaulac"; $database="blog"; mysql_connect('localhost:3306',$username,$password); @mysql_select_db($database) or die( "neiteku DB"); $query="SELECT * FROM komentari"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Komentari</center></b><br><br>"; $i=0; while ($i < $num) { $vards=mysql_result($result,$i,"vards"); $mails=mysql_result($result,$i,"mails"); $webs=mysql_result($result,$i,"webs"); $koments=mysql_result($result,$i,"koments"); <b>Vards:</b> echo "$vards <br>"; <b>Phone:</b> echo "$mails <br>"; <b>Mobile:</b> echo "$webs <br>"; <b>Koments:</b><br> echo "$koments <br>"; $i++; } ?> Un šitie errori metās! bet man ir nodefinēti mainigie!!! Notice: Undefined index: vards in c:\program files\apache group\apache\htdocs\tests\index.php on line 14 Notice: Undefined index: mails in c:\program files\apache group\apache\htdocs\tests\index.php on line 15 Notice: Undefined index: webs in c:\program files\apache group\apache\htdocs\tests\index.php on line 16 Notice: Undefined index: koments in c:\program files\apache group\apache\htdocs\tests\index.php on line 17 Parse error: parse error in c:\program files\apache group\apache\htdocs\tests\kom.php on line 25 Link to comment Share on other sites More sharing options...
Kavacky Posted April 11, 2005 Report Share Posted April 11, 2005 Jauki skaitīt rindiņas! Labi, ka te uzreiz varēja redzēt, kas par lietu: <b>Vards:</b> echo "$vards <br>"; <b>Phone:</b> echo "$mails <br>"; <b>Mobile:</b> echo "$webs <br>"; <b>Koments:</b><br> echo "$koments <br>"; Domā tas "<b>Vards:</b>" Tāpat izvadīsies? Liec takš visu iekš echo! echo '<b>Vards</b> '.$vards.'<br>'; utt. Link to comment Share on other sites More sharing options...
monZy Posted April 11, 2005 Author Report Share Posted April 11, 2005 Nu iekskaties: http://83.136.139.71/tests/ redzi, itkā neko nesaka, bet kad nospiezj Submit, vish neieraxta DB, un DB paliek tukša un neko nenolasa! Link to comment Share on other sites More sharing options...
Kavacky Posted April 11, 2005 Report Share Posted April 11, 2005 Paprovē: $query = "INSERT INTO `komentari` ( `vards`, `mails`, `webs`, `koments`) VALUES('$vards', '$mails', '$webs', '$koments')"; Un prasās arī teksta pārbaude, lai visādas sliktas lietas nevar sadarīt. Link to comment Share on other sites More sharing options...
monZy Posted April 12, 2005 Author Report Share Posted April 12, 2005 Liels paldies tev, viss aizgāja ;)) Link to comment Share on other sites More sharing options...
monZy Posted April 12, 2005 Author Report Share Posted April 12, 2005 tikai pasakat vienu kā lai ja laukumi ir tukši tad lai nepievienojas DB, bet kautvai tu ieej lapā vish pievieno pie DB tukšumus!!! Kā lai uztaisa lai nepievienotos, un kur man būtu jāieliek htmlentities lai neatļautu html tagus~ Link to comment Share on other sites More sharing options...
Kavacky Posted April 12, 2005 Report Share Posted April 12, 2005 Pārbaudi, vai mainīgais vispār ir padots, vai tas nav tukšs, vai tas ir tas, ko tu ceri tur sagaidīt. Un, kad veic pārbaudes, izlaid cauri visai apgraizīšanai. Link to comment Share on other sites More sharing options...
LorDRameX Posted April 12, 2005 Report Share Posted April 12, 2005 tikai pasakat vienu kā lai ja laukumi ir tukši tad lai nepievienojas DB, bet kautvai tu ieej lapā vish pievieno pie DB tukšumus!!! Kā lai uztaisa lai nepievienotos, un kur man būtu jāieliek htmlentities lai neatļautu html tagus~ 16228[/snapback] khm angliski SAPROTI ? lassiit ieksh PHP manualjaa par: EMPTY() TRIM() HTMLSPECIALCHARS() STRIP_TAGS() ADDSLASHES() STRIPSLASSHES() un visas tev nepiecieshamas darbiibas ir jaizveic PIRMS pievienoshans Datubazei (piemers noteikti nev tas labaakais un saprotamakais jo rakstu no galvas un ispejams ka pietruukst kada iekava (un seciba ar var buut savadaaka) $vards = strip_tags(addslashes(empty(trim($vards)))); $query = "INSERT INTO `komentari` ( `vards`, `mails`, `webs`, `koments`) VALUES('$vards', '$mails', '$webs', '$koments')"; Link to comment Share on other sites More sharing options...
v3rb0 Posted April 12, 2005 Report Share Posted April 12, 2005 caur empty() gan nevajag laist caur stringu pirms likšanas db. bool empty ( mixed var ) Link to comment Share on other sites More sharing options...
Kavacky Posted April 12, 2005 Report Share Posted April 12, 2005 Vispār caur ko un kādā secībā vajadzētu laist cauri? Kāds ir optimālais variants? Link to comment Share on other sites More sharing options...
v3rb0 Posted April 12, 2005 Report Share Posted April 12, 2005 Vispār caur ko un kādā secībā vajadzētu laist cauri? Kāds ir optimālais variants? 16234[/snapback] Man škiet ka Tavā gadījumā secība nav svarīga, jo tās nebūs ar aci jūtams. Ātrdarbību ietekmēs arī kādus stringus tu laidīsi tam caur. Cik es saprotu, tad pirmās būtu tās f-jas kas var saīsināt stringa garumu, tādejādi samazinot darbu nākošajām. Kuras?, izlasi ko katra no viņām dara, tad zināsi ko no tām Tev vajag un nākamreiz nebūs jāprasa forumā :P Link to comment Share on other sites More sharing options...
Recommended Posts