Artenis Posted July 24, 2008 Report Share Posted July 24, 2008 <?php $c=0; while($c<$num_c){ $id=mysql_result($r_aptauja_c,$c,"id"); $c++; } $a_idd = $id+1; $a=1; $i=0; while($i<$_POST['skaits']){ ?> <tr class="up_2"> <td></td> <td style="padding-left: 30px;">» <?php echo $a; ?>. aptaujas atbilde</td> <td><input name="atbilde[<?php echo $a; ?>]" type="text" value=""></td> <input type="hidden" name="a_id[<?php echo $a; ?>]" value="<?php echo $a_idd ?>" > </tr> <?php $a++; $i++; } ?> Ieraksts izskatās šādi: foreach($_POST['a_id'] as $v) { mysql_query("INSERT INTO $tb12 (a_id,atbilde) VALUES ('".$_POST['a_id'][$v]."','".$_POST['atbilde'][$v]."')"); echo $_POST['a_id'][$v].'<br>'; } Nekādu informāciju neieraksta, ieraksta tikai konkrēo daudzumu tukšo lauku.... Kāds var palabot, kādēļ man neieraksta... Link to comment Share on other sites More sharing options...
andrisp Posted July 24, 2008 Report Share Posted July 24, 2008 paskaties ar var_dump() kāds ir $_POST saturs. Link to comment Share on other sites More sharing options...
Artenis Posted July 24, 2008 Author Report Share Posted July 24, 2008 NULL NULL NULL Šitā uzmetās... Kaut kas neaiziet.... Variants? Link to comment Share on other sites More sharing options...
andrisp Posted July 24, 2008 Report Share Posted July 24, 2008 Parādi pilnu skriptu ar visiem form tagiem utt. Link to comment Share on other sites More sharing options...
Artenis Posted July 24, 2008 Author Report Share Posted July 24, 2008 (edited) Rekur ir form: http://paste.php.lv/7690 Rekur pievienošanas case: http://paste.php.lv/7691 To formu, kur jautājums pievieno bez problēmām... Paskatot source, tad visas vērtības ir vietā un tur kur jābut tā kā NULL to4na nevajadzēu būt... Edited July 24, 2008 by Artenis Link to comment Share on other sites More sharing options...
andrisp Posted July 24, 2008 Report Share Posted July 24, 2008 Skaidrs. Tam var_dump() padod $_POST masīvu nevis daļu no tā. Link to comment Share on other sites More sharing options...
Artenis Posted July 24, 2008 Author Report Share Posted July 24, 2008 array(3) { [1]=> string(2) "17" [2]=> string(2) "17" [3]=> string(2) "17" } array(3) { [1]=> string(2) "17" [2]=> string(2) "17" [3]=> string(2) "17" } array(3) { [1]=> string(2) "17" [2]=> string(2) "17" [3]=> string(2) "17" } Tipa tā? Link to comment Share on other sites More sharing options...
andrisp Posted July 24, 2008 Report Share Posted July 24, 2008 Nu tak! var_dump($_POST); Link to comment Share on other sites More sharing options...
Artenis Posted July 24, 2008 Author Report Share Posted July 24, 2008 (edited) array(4) { ["jautajums"]=> string(9) "Jautajums" ["ip"]=> string(9) "127.0.0.1" ["atbilde"]=> array(3) { [1]=> string(9) "atbilde_1" [2]=> string(9) "atbilde_2" [3]=> string(9) "atbilde_3" } ["a_id"]=> array(3) { [1]=> string(2) "20" [2]=> string(2) "20" [3]=> string(2) "20" } } array(4) { ["jautajums"]=> string(9) "Jautajums" ["ip"]=> string(9) "127.0.0.1" ["atbilde"]=> array(3) { [1]=> string(9) "atbilde_1" [2]=> string(9) "atbilde_2" [3]=> string(9) "atbilde_3" } ["a_id"]=> array(3) { [1]=> string(2) "20" [2]=> string(2) "20" [3]=> string(2) "20" } } array(4) { ["jautajums"]=> string(9) "Jautajums" ["ip"]=> string(9) "127.0.0.1" ["atbilde"]=> array(3) { [1]=> string(9) "atbilde_1" [2]=> string(9) "atbilde_2" [3]=> string(9) "atbilde_3" } ["a_id"]=> array(3) { [1]=> string(2) "20" [2]=> string(2) "20" [3]=> string(2) "20" } } Ko var no tā izsecināt? Edited July 24, 2008 by Artenis Link to comment Share on other sites More sharing options...
andrisp Posted July 24, 2008 Report Share Posted July 24, 2008 Ieliec to var_dump() starp <pre> un pēti, kur masīvā ir kļūda. Link to comment Share on other sites More sharing options...
indoom Posted July 24, 2008 Report Share Posted July 24, 2008 (edited) Daudz neiedziļinoties jau pirmajā rakstā tā "foreach($_POST['a_id'] as $v) {" vieta izskatās aizdomīga, kur iekš loopa tiek ņemti $_POST['a_id'][$v] Visdrīzāk tajās vietās vajadzīgs tikai $v, jo tas jau ir value. Ja rakstītu foreach($_POST['a_id'] as $k=>$v) { } tad varētu izmantot $_POST['a_id'][$k], lai atgrieztu posta saturu, bet ērtāk uzreiz ņemt $v. echo $v.'<br>'; Vispār izskatās, ka tev tieši tas $k ir vajadzīgs, tur kur ir $_POST['atbilde'][$k] mysql querijā foreach($_POST['a_id'] as $k=>$v) { mysql_query("INSERT INTO $tb12 (a_id,atbilde) VALUES ('".$v."','".$_POST['atbilde'][$k]."')"); echo $v.'<br>'; } Tik neaizmirsti iztīrīt posta values pirms inserto tabulā. Edited July 24, 2008 by indoom Link to comment Share on other sites More sharing options...
Artenis Posted July 24, 2008 Author Report Share Posted July 24, 2008 indoom milzīgs paldies, aizgāja! :) Link to comment Share on other sites More sharing options...
kasisppr Posted July 24, 2008 Report Share Posted July 24, 2008 Vēl viens ieteikums, kurš te ļoti bieži tiek pieminēts, saistībā ar aizsardzību pret SQL injekcijām. Nepadod pa tiesho $_POST, $_GET mainīgo uz datubāzi bez jebkādas apstādes, vismaz mysql_real_escape_string() vai mysql_escape_string() izmanto stringiem un intval() veseliem skaitlļem. Link to comment Share on other sites More sharing options...
Recommended Posts