Note that there are some explanatory texts on larger screens.

plurals
  1. POconstruct sql code to limit form submit
    primarykey
    data
    text
    <p>I allow people to submit images and I need to limit their submits to not more than 5 in a day. I just need your help to construct the sql code as rest of things are prepared. I would rather not use solutions based on sessions and cookies. IP based solution is not rock-solid either but for me it is okay and better than the other two. Just so you know the site is built on wordpress and I know nothing about mysql. </p> <p>EDIT : <em>I am already trying to construct the code below in EFFORTS UPDATE. Please take a look.</em></p> <hr> <p><strong>HERE IS WHAT I AM DOING</strong> : I already have a table in mysql for this function, named someprefix_limit_uploads. I will log the ip and date of the person who will use the form first time and save it to database on form submit, with help of hidden fields, example - <code>&lt;input type="hidden" name="uploader_ip" value="&lt;?php echo $uploader_ip;?&gt;"/&gt;</code>. Then I will insert the values to the table with something like below, since I am using wordpress so my code will look like so :</p> <pre><code>global $wpdb; require_once('../../../wp-load.php'); $upload_date = strip_tags($_POST['upload_date']); $uploader_ip = strip_tags($_POST['uploader_ip']); $table_name = $wpdb-&gt;someprefix . "limit_uploads"; $wpdb-&gt;insert( $table_name, array( 'rec_upload_date' =&gt; $upload_date, 'rec_uploader_ip' =&gt; $uploader_ip )); </code></pre> <hr> <p><strong>HERE IS WHERE I AM STUCK</strong> : Now for the code in the page which contains the form, I need to wrap the form in <code>if_statement</code>. Basically the script must hide the form after 5 submits within 24 hour. Here is an example of what the final code may look like.</p> <pre><code>global $wpdb; $results = $wpdb-&gt;get_results("COUNT xyz xyz xyz xyz xyz xyz xyz xyz xyz "); if(//there are more than 5 submits from same ip on same day) { echo "no more than 5 uploads allowed."; } else { &lt;form id="upload-images" action="" method="POST"&gt; //contents of the form &lt;/form&gt; } </code></pre> <hr> <blockquote> <p>Bottomline: It must be evident by now that I need help with the second block of the code. As I am not even sure I should use COUNT or SELECT, if yes then how. I will appreciate a little help here, also please point out if there is something wrong in my approach.</p> </blockquote> <hr> <p><strong>EFFORTS UPDATE :</strong></p> <p>I figure the sql query has to be something like this but missing some elements :</p> <pre><code>SELECT COUNT(*) **missing_some_code_here** FROM someprefix_limit_uploads WHERE rec_uploader_ip = $uploader_ip; AND rec_upload_date = $upload_date; </code></pre> <p>and then in my page</p> <pre><code>if (**missing_some_code_here** &gt; 5) { echo "no more than 5 uploads allowed."; return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload