Form submit fails on second time submit

Hello I am working on wordpress and below is my php code. I show images by fetching their path from database and have a vote button with every image and when it is clicked the vote is added to the votes table. After vote is added I want to show that queue of images again with updated votes for all the images. I am doing this successfully but when I press vote button for the second time to add second vote I get a message that database insertion failed. Below is my code and snapshot of how my page looks and what is the error are all mentioned below. Images are comming from articles table which has 1:N relationship with votes table.

PHP Code

if(isset($_POST['submit'])){ $ccc = $_POST['comp']; $cat =$_POST['category']; global $wpdb; $compp = $wpdb->get_var("SELECT competition FROM competition ORDER BY cid DESC LIMIT 1"); $userid = $_POST['id']; $myvote = 1; if($wpdb->insert( 'zvotes', array( 'zvotes' => $myvote, 'zcompetition' => $compp, 'aid' => $userid ) ) == false) wp_die('Database Insertion failed'); else echo 'your vote was successfully recorded'; //show the updated results //get current competition value $sqll = "SELECT articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title, Sum(zvotes.zvotes) AS votessum FROM articles LEFT JOIN zvotes on articles.aid=zvotes.aid WHERE articles.category = '$cat' && articles.competition = '$ccc' GROUP BY articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title ORDER BY votessum"; $results = $wpdb->get_results($wpdb->prepare($sqll)) or die(mysql_error()); foreach( $results as $result ) { echo '<form action="" method="post">'; echo "<input name='category' type='hidden' value='$result->category'>"; echo $result->title.'<br>'; echo "<img src='$result->path' width='150' height='150' >" . '<br><br>'; echo $result->body.'<br>'; echo "<input name='comp' type='hidden' value='$result->competition'>"; echo $result->username.'<br>'; echo $result->votessum.'<br>'; echo "<input style='margin-bottom:30px;' value='vote' name='submit' type='submit'/></form>"; }//end of foreach } ///////////////////////////////////////////////////////////////////////// // drop down echo '<form action="" method="post">'; echo '<select name="category" id="category" style="width:250px; background-color:lightgrey;">'; echo '<option value="" disabled="disabled" selected="selected" ">Select category</option>'; echo '<option value="My Testimony">My Testimony</option>'; echo '<option value="Love & Relationships">Love & Relationships</option>'; echo '<option value="Miscellaneous">Miscellaneous</option>'; echo '</select>'; echo '<input type="submit" name="a" value="Search" style="margin-left:15px; margin-bottom:15px;">'; echo '</form>'; //show after drop down value is selected if(isset($_POST['a'])){ //echo "zeeshanaslamdurrani". "<br>"; echo do_shortcode('[ujicountdown id="Photos Contest" expire="2015/04/30 00:00" hide="true" url="" subscr="sdf" recurring="" rectype="second" repeats=""]'); global $wpdb; //get current competition value $cat =$_POST['category']; $comp = $wpdb->get_var("SELECT competition FROM competition ORDER BY cid DESC LIMIT 1"); //echo $comp; $comp = $wpdb->get_var("SELECT competition FROM competition ORDER BY cid DESC LIMIT 1"); echo "current competition is ". $comp; $sqll = "SELECT articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title, Sum(zvotes.zvotes) AS votessum FROM articles LEFT JOIN zvotes on articles.aid=zvotes.aid WHERE articles.category = '$cat' && articles.competition = '$comp' GROUP BY articles.aid, articles.username, articles.competition, articles.path, articles.category, articles.title ORDER BY votessum"; $results = $wpdb->get_results($wpdb->prepare($sqll)) or die(mysql_error()); foreach( $results as $result ) { echo '<form action="" method="post">'; echo "<input name='category' type='hidden' value='$result->category'>"; echo "<input name='id' type='hidden' value='$result->aid'>"; echo $result->title.'<br>'; echo "<img src='$result->path' width='150' height='150' >" . '<br><br>'; echo $result->body.'<br>'; echo "<input name='comp' type='hidden' value='$result->competition'>"; echo $result->username.'<br>'; echo $result->votessum.'<br>'; echo "<input style='margin-bottom:30px;' value='vote' name='submit' type='submit'/></form>"; }//end of foreach }//end of isset

My page Form submit fails on second time submit

After vote(which is a form submit button) is pressed once Form submit fails on second time submit

Error on second pressing vote button second time after page refresh Form submit fails on second time submit

votes table Form submit fails on second time submit

Articles table (articles table has 1 to many relationship with votes table) Form submit fails on second time submit

Category:php Views:1 Time:2018-02-10

Related post

  • Javascript php validation, form submiting on the second time submit after filling one text box out of 2 textboxes 2014-05-26

    Im trying php javascript form validation. There are 2 input fields. And all the 2 fields are manditory. For the first time javascript validation is working and form is not submiting, but when i fill the one text box value of validation error , then t

  • RSpec doesn't remove DB record so it fails the second time it runs 2011-06-07

    This is from Michael Hartl's book, section 8.4. RSpec is testing a successful signup but is fails because the email address isn't unique. So if I go into the code and update the email address in the spec, it works the first time I run it but not the

  • Symfony2 - Non-mapped Multiselect Form Type fails to render and submit 2015-01-21

    I need to create a multi-select form for collecting student ethnicities which is a one-to-many relationship using symfony2, doctrine2-orm, and twig. I also have a race field where I created a form type to handle that data, which I implemented success

  • Keep form data when form is loaded a second time 2011-03-01

    I have a from that does two things. Gets user text input. Users can select an image or upload their own. Problem occurs when user uploads their image. The file field must submit the information to upload the image. It does all works. But when the for

  • glReadPixels read failed on second-time 2011-06-16

    Following code works fine const char *title = "glReadOutput"; Mat out1, out2; out1.create(screenHeight,screenWidth, CV_8UC3); out2.create(screenHeight,screenWidth, CV_8UC3); RenderObject(); glReadPixels(0, 0, screenWidth, screenHeight, GL_BGR, GL_UNS

  • jQuery $(this) works in Firefox; fails the second time in Internet Explorer? 2011-01-18

    My little jQuery snippet works great in Firefox; but fails in IE. This is particularly annoying and mysterious because a very similar command, just a few lines earlier, does work in IE. Any ideas? $('.bio_text').clone() .each ( function(index, value)

  • vba insert fails second time 2012-07-01

    I have an Excel Macro which has a problem inserting a line into an Excel2010 xlsb workbook when running Windows 7 64 bit on a dell 14r laptop with 4 gig ram and a 50 gig disk. When I open the spreadsheet, the code works the first time, but fails the

  • Is it possible to do a better programming job the second time around? 2009-04-14

    I hate the way this sounds but Joel says "It's important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time." I want to not believe this. Am I really

  • if(isset($_POST['submit'])) twice not working second time 2011-03-11

    I am pulling my hair out. I had this working earlier. My confirm.php checks variables from the previous page's form. Then echos them so the viewer can confirm the answers. If everything looks good they can click the paypal image name="submit" and it

  • embedded iframe form used to upload files. Doesn't work on first submit, works on second 2010-03-06

    I have an embedded iframe form which takes a file from a type="file" form field and uploads it using a progress bar: <form action="sell_upload.php" method="post" id="uploadform" enctype="multipart/form-data"> <input type="hidden" name="UPLOA

  • Form submit fails after jQuery reload of the forum 2010-11-17

    I've hit this problem a few times, and I've always just found a work around, but this time that would probably be impossible. The problem is this. I have a form inside a DIV, and I submit the form using jQuery AJAX and then reload the form with the n

  • Form submit fails to generate query parameters if input element's are in multple div's 2011-07-26

    If I have a form element as given below, then calling the form's submit will automatically generate the request body/query parameters in the url-encoded form as "username={username}&password={password}&submit=submit" where values in {} are ta

  • Submit PayPal form & Update Database at same time 2011-09-05

    If I use the standard PayPal form for payments can I also update my db at the same time, by changing the code slightly to include the update details? This is the standard PayPal payment form I want to use - Will change as necessary.. <form action=

  • form submit fails to do as I want it to 2012-02-13

    <?=form_open('register');?> <table> <tr> <td><label for="register_name">Username : </label></td> <td><input type="text" name="register_name" readonly="true" value="<?=$_POST['username']?>"/>

  • Why does my LINQ to SQL query fail the first time ("Row Not Found or Changed") and succeed the second time? 2009-12-09

    I'm using LINQ to SQL in ASP.NET MVC. I wrote some new code to update Orders in our system, and as far as I can tell it's exactly like a hundred other similar pieces of code I've written (grab the object, update some fields, submit changes). This tim

  • Second Javascript form POST fails in Chrome, works in IE and FF 2011-07-28

    I'm opening a new window via a javascript POST in response to a user click in a flash application. The user may close the new window and want to re-open it by clicking the button on the first page again. Since I have to pass some large arguments to t

  • Controls disposed second time form is opened 2010-11-08

    The first time I open one of my child forms from the main form it opens normally. If I close the first instance of the child form and then reopen it however I get a crash the first time I try to call CreateGraphics() outside of the OnPaint() method.

  • Submit Return False, But Still Submit Form - PHP, Javascript, AJAX, CodeIgniter 2010-11-19

    This is probably going to sound backwards. I need for a form to submit return false, but still submit the form. I have a form being pulled into a page via ajax (jquery load function), and on submit I'd like to display a graphic and some text in the s

  • Remember form value when return back to submit due to some error 2011-06-24

    After filling the form when submit, accidentally due to some filling error ,the form is not submit and return to back,in this condition the value of all text box is blank. i want to stable value of all fields in this condition . I'm using php with sm

  • An Ektron form in a dropzone doesn't submit when logged out (8.0.1 SP1) 2012-02-29

    We are using Ektron 8.0.1 SP1 We have a client who wants to put up one-question forms on their homepage and change them out regularly. We created a dropzone on the homepage and that worked perfectly for allowing them to change out the form whenever t

  • Error: Form elements must not be named "submit" 2009-07-30

    When submitting an upload form, an alert shows up: Error: Form elements must not be named "submit". And no, I don't have any form elements with the name submit. I'm using jQuery version 1.3.2. What's the fix for this? --------------Solutions---------

  • Tooltips won't show second time form is created 2009-08-24

    I have a dialog box with controls that is popped up and when a control is moused over the controls a tooltip is displayed. However, if I close the box then re-display it no tooltips will work. Here is a portion of my code. I am initializing tooltipOn

  • Function fails on the second time i call it 2010-01-15

    <script language="javascript"> function refresh() { try { xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} xmlhttp.onreadystatechange = triggered; xmlhttp.open("GET", "data.php"); xm

  • GWT Query fails second time -only 2010-06-15

    HI, I have a visualization function in GWT which calls for two instances of the same panels - two queries. Now, suppose one url is A and the other url is B. Here, I am facing an issue in that if A is called first, then both A and B works. If B is cal

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.233 (s). 11 q(s)