realfun Posted March 9, 2010 Report Share Posted March 9, 2010 (edited) Es esmu izveidojis shadu scriptu <?php //Pieslēgšanās datubāzei $db_host = 'localhost'; $db_user = 'root'; $db_password = 'real112'; $db_name = 'sistema'; $connection = @mysql_connect($db_host, $db_user, $db_password) or die(mysql_error()); mysql_select_db($db_name, $connection); mysql_query("SET NAMES utf8"); //Ievietošana datubazē $sql="INSERT INTO viesene (vards, lapa, zinja) VALUES ('$_POST[vards]','$_POST[lapa]','$_POST[zinja]')"; if (!mysql_query($sql,$connection)) echo "<span class='ok'>Pievienots</span><br />"; else { echo "<span class='error'>Kāds lauks palika tukšs!</span><br />"; } //Izvilkšana $result = mysql_query("SELECT * FROM viesene"); while($row = mysql_fetch_array($result)) { echo "<br>"; echo "<br>" . $row['vards'] . "</td>"; echo "<br>" . $row['lapa'] . "</td>"; echo "<br>" . $row['zinja'] . "</td>"; echo "</br>"; } mysql_close($connection) ?> <form method="post" action=""> Vards: <br /> <input type="text" name="vards"><br /> majaslapa: <br /> <input type="text" name="lapa"><br /> Vestule: <br /> <textarea name="zinja" cols="60" rows="10"></textarea><br /> <input type="submit" value="pievienot"> </form> itka viss ok vinjsh ievada bazee un izvada bet ka lapu refresho vinjsh atkal izvada to pas un ta visu laiku CREATE TABLE `sistema`.`viesene` ( `id` INT NOT NULL AUTO_INCREMENT , `vards` VARCHAR( 255 ) NOT NULL , `lapa` VARCHAR( 255 ) NOT NULL , `zinja` TEXT NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = InnoDB; reku msql kods ja gadijuma vesapratat ludzu palidzat ja varat izlabojat ja ne ludzu pasakat kapec ta ir! nevarētu but vaina ar to action? Edited March 9, 2010 by realfun Quote Link to comment Share on other sites More sharing options...
2easy Posted March 9, 2010 Report Share Posted March 9, 2010 (edited) lai pēc refreša pa jaunam netiktu sūtīti dati, pēc inserta vajag uztaisīt redirect uz esošo lapu (vai uz "vieseni", ja tā un pievienošana ir dažādos failos vai adresēs) header('Location: ' . $_SERVER['REQUEST_URI']); Edited March 9, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
mounkuls Posted March 9, 2010 Report Share Posted March 9, 2010 (edited) Un vēlams URL vēl klāt piekabināt randskaitli, savādāk ej nu sazini vai ar kešoto nesaber pilnu bāzi kā no ložmetēja:) Un vēl tai kodā neredzu ka čekotu vispār ir vai nav post dati un tad jau attiecīgi raksta bāzē vai tikai izvada tekstus un formu. Vēl ieteikums likt bāzē arī ieraksta laiku, var noderēt. Edited March 9, 2010 by mounkuls Quote Link to comment Share on other sites More sharing options...
realfun Posted March 9, 2010 Author Report Share Posted March 9, 2010 ok tnx par ieteikumu bet man met eror lapu ka ielieku to redirect! bet iespejams ka pats nepareiz kaut ko izdariju japarskata! Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted March 9, 2010 Report Share Posted March 9, 2010 Ljauj mineet - headers already sent? ^_^ Quote Link to comment Share on other sites More sharing options...
2easy Posted March 9, 2010 Report Share Posted March 9, 2010 (edited) droši vien bezgalīgais redirect ;) ieliec tajā formā darbību <input type="hidden" name="action" value="pievienot" /> un pievienošanu veic tikai tad, kad atnāk forma ar attiecīgo darbību if ($_POST['action'] == 'pievienot') { ... // insert in db un beigās redirect } droši vien kodē savu pirmo formu, ja? ;) Edited March 9, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
realfun Posted March 10, 2010 Author Report Share Posted March 10, 2010 jap! tnx Quote Link to comment Share on other sites More sharing options...
realfun Posted March 10, 2010 Author Report Share Posted March 10, 2010 aa un jaa man vinjš man met tagad erroru Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\mans\index.php:23) in C:\xampp\htdocs\mans\index.php on line 40 un tapat visu laiku ar refreshu met bazee iekšā un velk arā! Quote Link to comment Share on other sites More sharing options...
2easy Posted March 10, 2010 Report Share Posted March 10, 2010 njaa ar topika nopinošana ir par maz :D:D:D http://php.lv/f/topic/7294-headers-already-sent/ Quote Link to comment Share on other sites More sharing options...
php newbie Posted March 10, 2010 Report Share Posted March 10, 2010 un neaizmirsti par aizsardzību no sql injekcijas un xss Quote Link to comment Share on other sites More sharing options...
realfun Posted March 10, 2010 Author Report Share Posted March 10, 2010 (edited) Eu bet ja es piemeram to dazi taissitu atseviska skripta un pectam palaistu ar fopen nevareetu sanaakt? aa un ar fopen var atvert php vailus? Edited March 10, 2010 by realfun Quote Link to comment Share on other sites More sharing options...
thesnarkie Posted March 10, 2010 Report Share Posted March 10, 2010 (edited) Vai vieglāk nebūtu to, ko tu tur gribi panākt izdarīt ar jquery? Edited March 10, 2010 by thesnarkie Quote Link to comment Share on other sites More sharing options...
2easy Posted March 10, 2010 Report Share Posted March 10, 2010 un neaizmirsti par aizsardzību no sql injekcijas un xss lai varētu aizmirst, vispirms tas ir jāzin :D:D:D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.