Jump to content
php.lv forumi

Sūtas tukši posti


Pieduriens

Recommended Posts

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!

Link to comment
Share on other sites

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 by y2ok
Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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 by y2ok
Link to comment
Share on other sites

[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 by Pieduriens
Link to comment
Share on other sites

feedingbaby.jpg

 

<?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>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...