Pieduriens Posted August 3, 2012 Report Share Posted August 3, 2012 Labdien php.lv forumieši. Saskāros ar problēmu, kuru pēc manām domām var novērst ar isset, taču, joprojām pie lapas atvēršanas vai atjaunināšanas tiek sūtīti tukši posti no laukiem.. <fieldset> <?php if (!isset($_POST['submit'])){ $title = $_POST['title']; $text = $_POST['text']; $sql="INSERT INTO pages (title, content) VALUES ('$_POST[title]','$_POST[text]')";} if (!mysql_query($sql,$conn)) { die('Error: ' . mysql_error()); } mysql_close($conn); ?> <form action="index.php" method="POST"> Add Page<br /> Title <input type="text" name="title" value="" /><br /> Text:<textarea name="text" cols=50 rows=8></textarea> <input type="submit" value="Add Page" /> </form> </fieldset> Netieku skaidrībā Paldies! Quote Link to comment Share on other sites More sharing options...
y2ok Posted August 3, 2012 Report Share Posted August 3, 2012 (edited) Nu php kodā viss ir ok, un viņš izpilda visu kas ir starp pirmā if'a, ja nekas nav nospiests. Respektīvi, tu palaid pirmo if'u ja nav nospiesta submit poga, tātad - pie katras lapas ielādes. Noņem ! pirmajam if'am un viss ies. Edited August 3, 2012 by y2ok Quote Link to comment Share on other sites More sharing options...
codez Posted August 3, 2012 Report Share Posted August 3, 2012 izlasi savu kodu - tur teikts, ka - ja nav iesetots $_post['submit'], tad inserto db. Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted August 3, 2012 Author Report Share Posted August 3, 2012 Nu jā, paldies. Taču tagat noņemot no isset "!" zīmi, rādas: Error: Query was empty. Forma vispār nepostējas uz db. <?php if (isset($_POST['submit'])){ $title = $_POST['title']; $text = $_POST['text']; $sql="INSERT INTO pages (title, content) VALUES ('$_POST[title]','$_POST[text]')";} if (!mysql_query($sql,$conn)) { die('Error: ' . mysql_error()); } mysql_close($conn); ?> <fieldset> <form action="addpage.php" method="POST"> Add Page<br /> Title <input type="text" name="title" value="" /><br /> Text:<textarea name="text" cols=50 rows=8></textarea> <input type="submit" value="Add Page" /> </form> </fieldset> Quote Link to comment Share on other sites More sharing options...
y2ok Posted August 3, 2012 Report Share Posted August 3, 2012 (edited) if (!mysql_query($sql,$conn)) { die('Error: ' . mysql_error()); } mysql_close($conn); Ieliec starp pirmā if'a. Tu viņu arī palaid pie katras lapas ielādes, un tā kā tagad tev $sql mainīgais tikai izveidojas pēc submit pogas nospiešanas, mysql_query() tiek padots tukšs variablis. P.S. Kāpēc tu definē mainīgos un pēc tam viņus neizmanto? P.S.S. Iesaku jau tagad sākt mācīties likt tabus un rakstīt skaistu kodu. Edited August 3, 2012 by y2ok Quote Link to comment Share on other sites More sharing options...
Pieduriens Posted August 3, 2012 Author Report Share Posted August 3, 2012 (edited) [color=#282828][font=helvetica, arial, sans-serif]<pre class="prettyprint" style="margin-top: 0px; margin-bottom: 0px; margin-left: 10px; padding: 5px; background-color: rgb(248, 248, 248); border: 1px solid rgb(201, 201, 201); overflow: auto; font-size: 11px; line-height: 15px; color: rgb(40, 40, 40); ">[/font][/color][color=#000088][font=helvetica, arial, sans-serif]if[/font][/color][color=#000000][font=helvetica, arial, sans-serif] [/font][/color][color=#666600][font=helvetica, arial, sans-serif](![/font][/color][color=#000000][font=helvetica, arial, sans-serif]mysql_query[/font][/color][color=#666600][font=helvetica, arial, sans-serif]([/font][/color][color=#000000][font=helvetica, arial, sans-serif]$sql[/font][/color][color=#666600][font=helvetica, arial, sans-serif],[/font][/color][color=#000000][font=helvetica, arial, sans-serif]$conn[/font][/color][color=#666600][font=helvetica, arial, sans-serif]))[/font][/color][color=#000000][font=helvetica, arial, sans-serif] [/font][/color][color=#666600][font=helvetica, arial, sans-serif]{[/font][/color][color=#000000][font=helvetica, arial, sans-serif] [/font][/color][color=#000088][font=helvetica, arial, sans-serif]die[/font][/color][color=#666600][font=helvetica, arial, sans-serif]([/font][/color][color=#008800][font=helvetica, arial, sans-serif]'Error: '[/font][/color][color=#000000][font=helvetica, arial, sans-serif] [/font][/color][color=#666600][font=helvetica, arial, sans-serif].[/font][/color][color=#000000][font=helvetica, arial, sans-serif] mysql_error[/font][/color][color=#666600][font=helvetica, arial, sans-serif]());[/font][/color][color=#000000][font=helvetica, arial, sans-serif] [/font][/color][color=#666600][font=helvetica, arial, sans-serif]}[/font][/color][color=#000000][font=helvetica, arial, sans-serif] mysql_close[/font][/color][color=#666600][font=helvetica, arial, sans-serif]([/font][/color][color=#000000][font=helvetica, arial, sans-serif]$conn[/font][/color][color=#666600][font=helvetica, arial, sans-serif]);[/font][/color][color=#282828][font=helvetica, arial, sans-serif]</pre>[/font][/color]Lūdzu paskaido? Edited August 3, 2012 by Pieduriens Quote Link to comment Share on other sites More sharing options...
y2ok Posted August 3, 2012 Report Share Posted August 3, 2012 <?php if (isset($_POST['submit'])){ $title = $_POST['title']; $text = $_POST['text']; $sql="INSERT INTO pages (title, content) VALUES ('$_POST[title]','$_POST[text]')"; if (!mysql_query($sql,$conn)) { die('Error: ' . mysql_error()); } mysql_close($conn); } ?> <fieldset> <form action="addpage.php" method="POST"> Add Page<br /> Title <input type="text" name="title" value="" /><br /> Text:<textarea name="text" cols=50 rows=8></textarea> <input type="submit" value="Add Page" /> </form> </fieldset> Quote Link to comment Share on other sites More sharing options...
daGrevis Posted August 3, 2012 Report Share Posted August 3, 2012 _empty_ funkcija vai `$x === ''`. 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.