-4

Basically what I have is some form and this:

<?php

require 'inc/conn.php'; 

$sql="INSERT INTO objednavky ( kdo, kdy, m1, mm1, m2, mm2, m3, mm3 )
VALUES
('$_POST[tkdo]','$_POST[thed]','$_POST[obb1]','$_POST[tmm1]',
'$_POST[obb2]','$_POST[tmm2]','$_POST[obb3]','$_POST[tmm3]')";

if (!mysql_query($sql,$con))
{
  die('Error: ' . mysql_error());
}

header('Location: http://www.juxcore.com/x/vita/protected.php');

mysql_close($con);

I need to make the form non-submitable in case for exmaple is Thursday and the last moment when you can submit it is on Wednesday 18pm. Thanks for help

hakre
  • 193,403
  • 52
  • 435
  • 836
user1505027
  • 323
  • 2
  • 8
  • 14
  • 3
    You are using [an obsolete database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also exposing yourself to [SQL injection attacks](http://bobby-tables.com/) that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Oct 25 '12 at 12:28
  • 1
    Have you tried anything so far ? – Touki Oct 25 '12 at 12:40
  • So when receiving the form, check if it's past a certain time and don't insert into the database if so... tried something like that? – deceze Oct 25 '12 at 12:42

4 Answers4

2

It seems your question is really an HTML/Javascript question and not PHP/SQL.

Because at first glance I would say change the HTML with Javascript so that they cant submit the form.

document.getElementById("myform").action = "";

... would prevent submitting. There are many ways, including switching the form to a div:

document.getElementById("myform").setAttribute("type","div");

Or, remove the submit button from display so they cant click on it:

document.getElementById("mysubmit").style.display="none";

EDIT: oh and i completely forgot the obvious way, use form validation. This way they cant park on the URL until after wednesday and still submit in HTML

<form ... onsubmit="return validateForm()">

Just write the javascript function validateForm (similar to the php below) to return false to cancel the submit. I dont like giving w3school links but here is a nice clean example: http://www.w3schools.com/js/js_form_validation.asp

Anyhow, there are many more ways. Just do which ever one on the right day, use javascript's new Date().getDay() and new Date().getHours() to determine when.

(this is also an example of the two main ways to change an element's attributes).

I guess this doesn't stop them from submitting directly from the address line, which in case, you would need to edit your PHP, use the Date() object:

$day = Date("w");
if ( $day == 4 || $day == 5 ) {
    $time = Date("G");
    if ( $day != 5 || $time < 18 ) {
        if (!mysql_query($sql,$con)) die('Error: ' . mysql_error());
    }
}

I would suggest to do both, a HTML/Javascript way of controlling it with the same control built into your server.

Pimp Trizkit
  • 19,142
  • 5
  • 25
  • 39
0

You can append some JS into your view, to make form non-submitable.

My ideia is:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    <?php if($currentDay < $dontSubmitFormDay):?>
         $('#myForm').submit(function(){
              return false;
         });
    <?php endif;?>
});
</script>
0

You need to get the timestamp for that day wednesday 6 p.m. Then every time a user submits the form, get the timestamp of that exact time and do a comparison:

if(timenow

William The Dev
  • 505
  • 1
  • 6
  • 16
0

First of all do not reply on the client (browser) clock. This can be fudged if the end user so desires. Instead create a session using PHP and mark the date/time for the last date/time the form can be submitted. Upon receipt of that form use the servers date/time (the one that cannot be fudged by the end user) to do the check.

In this way you can be absolutely sure that more security in not enabling forms to be submitted is not thwarted.

However you can use Javascript to make the users experience better but do not reply on date/time of the client for your database protection.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127