Patrick Parcheta Patrick Parcheta - 6 months ago 13
SQL Question

Simple form not working

I just have created custom form in Wordpress to add some comments fastly.
I have write simple form:

<form method='post' method='xxxx.com/global/wp-content/themes/theme/autoblog/skryptkom.php'>
<h3>Wpisz komentarze</h3>
<p>
<textarea name="komentarzex" rows="10" cols="30">
1 komentarz = 1 linia
</textarea>
</p>
<h3>Wpisz nazwy uzytkowników</h3>
<p>
<textarea name="uzytkownicxy" rows="10" cols="30">
1 uyztkownik = 1 linia
</textarea>
</p>
<h3> Dodatkowe ustawienia</h3>
Ile komentarzy musi mieć wpis aby dodało do niego dodatkowe komentarze: <input type="text" name="ilekomentarzy" value="0"><br>
Do ilu wpisów dodack komantarze? : <input type="text" name="ileposotownaeraz" value="200"><br>
Wpisz przedzial ile ma dodać komentarzy do wpisu : od <input type="text" name="odkoms" value="5"> do <input type="text" name="dokoms" value="20"><br>
<p>
<input type="submit" value="Dodaj komentarze" name="dodajmeykurwa" />
</p>
</form>


And its display in admin page very good: http://prntscr.com/b3x3e3

But when I try to post comments its not working fine :(

Here is my code to do action:

<?php
if(isset($_POST['dodajmeykurwa'])) {
require_once('spintax.php' );
$komentarze = $_POST['komentarzex'];
$uzytkownicy = $_POST['uzytkownicxy'];

$rakoms = preg_split("/\r\n|\n|\r/", $komentarze);
$rausers = preg_split("/\r\n|\n|\r/", $uzytkownicy);

require_once ('wp-blog-header.php');
// ile koemntarzy musi miec post aby do niego dodac komentarz

$ilekomsmusimiec = $_POST['ilekomentarzy'];
$limitdodanychpostow = $_POST['ileposotownaeraz'];
global $wpdb;
// pobranie postów z liczbą komentarzy 0
$posty = $wpdb->get_results("SELECT id, comment_count FROM wp_posts WHERE post_type='post' AND post_status='publish' AND comment_count= $ilekomsmusimiec ORDER BY RAND() LIMIT $limitdodanychpostow");

$spintax->process($string);

if ($posty)
{
foreach ($posty as $p)
{
// losowe nicki i komentarze
shuffle($rakoms);
shuffle($rausers);
$oidkoskoms = $_POST['odkoms'];
$dokadkoms = $_POST['dokoms'];
for ($i = $oidkoskoms, $size = $dokadkoms; $i < $size; $i++)
{
// ustawienia komentarza - wartości
$data = array(
'comment_post_ID' => $p->id,
'comment_author' => $spintax->process($rausers[$i]),
'comment_author_email' => 'admin@admin.com',
'comment_author_url' => 'http://',
'comment_content' => $spintax->process($rakoms[$i]),
'comment_type' => '',
'comment_parent' => 0,
'user_id' => rand(1, 100),
'comment_author_IP' => '127.0.0.1',
'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
'comment_date' => current_time('mysql'),
'comment_approved' => 1,
);
wp_insert_comment($data);
}
}
} else
{
echo "Brak postow do ktorych mozna dodac komenatarze";
}
}
?>


What I have do wrong?

Answer

You have duplicated method attribute on your form opening tag:

This:

<form method='post' method='xxxx.com/global/wp-content/themes/theme/autoblog/skryptkom.php'>

Should be:

<form method='post' action='xxxx.com/global/wp-content/themes/theme/autoblog/skryptkom.php'>