...

View Full Version : Limit Form Submission P2



Chris-2k
05-22-2011, 10:07 PM
As i cudn't post in my old thread, cos vBull**** suckzors big time lol, im making this thread for help:

kk ive got this code:



<?php
if($_POST['submit']{

$formid = $_POST['submitdownloads'] //standard variables are easier to work with
if(isset($_COOKIE[$formid]){
if($_COOKIE[$formid] >= 2){
echo("Thanks for submitting your downloads, you have now reached the limit");
} else {
$_COOKIE[$formid] += 1;
echo("Submitting data...");
} else {
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
?>


and im getting this error:



Parse error: syntax error, unexpected T_IF in /home/chris2009/xtremeddl.net/submit.php on line 90


Im tryna make da form initialy, per session be able to be submitted 5x....

any help?

djh101
05-22-2011, 10:39 PM
http://www.rosettastone.com/spring5pay?language=eng&pc=sefreeship&cid=se-gg-5pay&gclid=CPnGrv3C_KgCFRNrgwodvW7LTg

Oh, and there's no ; after your $formid line.

Chris-2k
05-22-2011, 11:12 PM
Sorry about the language...

Fixed the ; here:


<?php
if($_POST['submit']{

$formid = $_POST['submitdownloads']; //standard variables are easier to work with
if(isset($_COOKIE[$formid]){
if($_COOKIE[$formid] >= 2){
echo("Thanks for submitting your downloads, you have now reached the limit");
} else {
$_COOKIE[$formid] += 1;
echo("Submitting data...");
} else {
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
?>


now got this error:


Parse error: syntax error, unexpected ';' in /home/chris2009/xtremeddl.net/submit.php on line 89


Edit: here's my whole form:



<form action="" method="post">

<?php
if($_POST['submit']{

$formid = $_POST['submitdownloads']; //standard variables are easier to work with
if(isset($_COOKIE[$formid]){
if($_COOKIE[$formid] >= 2){
echo("Thanks for submitting your downloads, you have now reached the limit");
} else {
$_COOKIE[$formid] += 1;
echo("Submitting data...");
} else {
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
?>


<?php
for($i=1;$i<=10;$i++) {
?>

<div>
<input type="text" class="inputbox" name="title[]" id="dt1" cols="80" />
<input type="text" class="inputbox" name="url[]" id="du1" />
<select name="type[]" class="inputbox smallbox" id="se1">
<?php
foreach($core->allowed_types as $at) {
echo '<option value="'.$at.'">'.$at.'</option>';
}
?>
</select></div>
<?php
}
?>

<div>Site Name: <input type="text" class="inputbox" name="sname" id="zname"/>
Site URL: <input type="text" class="inputbox" name="surl" id="zurl"/><br />
Email: <input type="text" class="inputbox" name="email" id="zemail"/>
<input type="submit" value="Submit Downloads" /></div>

<div><?=$core->error?>
<br /><?=$sub_success?></div>
</form>


do u have msn to chat?

djh101
05-22-2011, 11:50 PM
You are also missing a ) after your first if statement. "if($_POST['submit']){"

Just work on weeding out all instances that are missing characters. That should be it, but if you get any more errors, go to the line that the error is on and it shouldn't be too hard to find what's wrong.

EDIT: A few more errors
1. "if(isset($_COOKIE[$formid])){ "
2. echo "Thanks for submitting your downloads, you have now reached the limit" ; //echoed statements do not need to be surrounded in ()

tangoforce
05-22-2011, 11:54 PM
Don't use if (isset($_POST['submit'])) because internet explorer has a but and doesn't always send the submit button value. You should test for other data in the form instead.

Also can I perhaps interest you in the 2nd link in my signature? - You might find it useful for the future ;)

Chris-2k
05-23-2011, 12:27 AM
corrected all errors now,



<?php
if($_POST['submit']){

$formid = $_POST['submitdownloads']; //standard variables are easier to work with
if(isset($_COOKIE[$formid])
{
if($_COOKIE[$formid]) >= 2){
echo "Thanks for submitting your downloads, you have now reached the limit";
} else {
$_COOKIE[$formid] += 1;
echo "Submitting data...";
} else {
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
?>


now got:



Parse error: syntax error, unexpected '{' in /home/chris2009/xtremeddl.net/submit.php on line 91

djh101
05-23-2011, 12:57 AM
Refer to my last post. if(isset($_COOKIE[$formid]) is still missing a ). You have two opening parenthesis (one before isset and one before $_COOKIE) and only one ending parenthesis.

tangoforce
05-23-2011, 01:24 AM
There is also one closing parenthesis too many on this line - 2 closing and 1 opening:

if($_COOKIE[$formid]) >= 2){

djh101
05-23-2011, 02:02 AM
Ah yes, you added the ) after the wrong $_COOKIE[$formid].

Chris-2k
05-23-2011, 02:43 PM
hi,

fixed:



<?php
if($_POST['submit']){

$formid = $_POST['submitdownloads']; //standard variables are easier to work with
if(isset($_COOKIE[$formid])) {
if($_COOKIE[$formid]) >= 2 {
echo "Thanks for submitting your downloads, you have now reached the limit";
} else {
$_COOKIE[$formid] += 1;
echo "Submitting data...";
} else {
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
?>


now im getting:




Parse error: syntax error, unexpected T_IS_GREATER_OR_EQUAL in /home/chris2009/xtremeddl.net/submit.php on line 91


i dunno what this means, help?

As you might guess, I'm definitely not an avid PHPer :-)

Thanks for your help so far! I hope we can get this working!

tangoforce
05-23-2011, 05:19 PM
Change:


($_COOKIE[$formid]) >= 2


to:


($_COOKIE[$formid] >= 2 )

Chris-2k
05-23-2011, 07:09 PM
ok thx, done:



<?php
if($_POST['submit']){

$formid = $_POST['submitdownloads']; //standard variables are easier to work with
if(isset($_COOKIE[$formid])) {
if($_COOKIE[$formid] >= 2) {
echo "Thanks for submitting your downloads, you have now reached the limit";
} else {
$_COOKIE[$formid] += 1;
echo "Submitting data...";
} else {
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
?>


error:



Parse error: syntax error, unexpected T_ELSE in /home/chris2009/xtremeddl.net/submit.php on line 96


ty indeed.

djh101
05-23-2011, 10:53 PM
You cannot have an else statement after an else statement. I don't think I need to explain why.

tangoforce
05-23-2011, 11:14 PM
Along with having 2 else's, you also have a { too many. For the else problem you have two options: elseif or switch().

I've already recommended you take a look at the second link in my signature about coding styles. You chose to ignore that so i won't be assisting you to find the additional { as apparently you are above my help.

Chris-2k
05-23-2011, 11:31 PM
Okay ty, now i end the page like:



<?php

?>

and get this error:



Parse error: syntax error, unexpected $end in /home/chris2009/xtremeddl.net/submit.php on line 185


thats just how the Wcddl script ends pages.. any ideas?

Chris-2k
05-23-2011, 11:37 PM
Along with having 2 else's, you also have a { too many. For the else problem you have two options: elseif or switch().

I've already recommended you take a look at the second link in my signature about coding styles. You chose to ignore that so i won't be assisting you to find the additional { as apparently you are above my help.

srry m8, i missed ur post abt that... i will read it now...

u 2 guys have helped me alot +10 thanx

Chris-2k
05-24-2011, 12:20 AM
I read it, ur thread and edited my code, + took 1 of da else's out:



<?php
if($_POST['submit']){

$formid = $_POST['submitdownloads']; //standard variables are easier to work with

if(isset($_COOKIE[$formid])) {
if($_COOKIE[$formid] >= 2)
{
echo "Thanks for submitting your downloads, you have now reached the limit";
elseif
$_COOKIE[$formid] += 1;
echo "Submitting data...";
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
?>

error:


Parse error: syntax error, unexpected T_ELSE in /home/chris2009/xtremeddl.net/submit.php on line 95

tangoforce
05-24-2011, 12:28 AM
You've done more than remove one { symbol though haven't you chris.

I've got your previous and latest codes right in front of me in notepad++.

You've still not taken on board my comments about formatting. Look at the line:
if($_POST['submit']){

You still have a { at the end there don't you. If you read my thread properly, slowly and took time to understand it in detail you would have adjusted all of your code to this style not just the middle bit.

To stop prolonging the agony i've fixed your code for you. I won't do it again because you don't actually seem to be learning but instead just come here asking us to fix everything.



<?php
if($_POST['submit'])
{

$formid = $_POST['submitdownloads']; //standard variables are easier to work with

if(isset($_COOKIE[$formid]))
{
if($_COOKIE[$formid] >= 2)
{
echo "Thanks for submitting your downloads, you have now reached the limit";
}
else
{
$_COOKIE[$formid] += 1;
echo "Submitting data...";
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
}
?>


Finally i've pointed you to my signature twice now and you're still ignoring the bit about using if (isset($_POST['submit'])).

Chris-2k
05-24-2011, 12:35 AM
I have read tht an was going to ask what cud i try besides the submit button?

tangoforce
05-24-2011, 12:49 AM
The name of any other field in the form.

Chris-2k
05-24-2011, 12:51 AM
Ive added that code m8... and it seems the form is ignoring it completely as when i submit, it's allowed me 3 x submissions.

check it @:


http://xtremeddl.net/submit.php

tangoforce
05-24-2011, 02:44 PM
Which bit of code are we talking about? - You seem to do things in random order so i've no idea what you're talking about.

Chris-2k
05-24-2011, 03:22 PM
this:



<?php
if($_POST['submit'])
{

$formid = $_POST['submitdownloads']; //standard variables are easier to work with

if(isset($_COOKIE[$formid]))
{
if($_COOKIE[$formid] >= 2)
{
echo "Thanks for submitting your downloads, you have now reached the limit";
}
else
{
$_COOKIE[$formid] += 1;
echo "Submitting data...";
setcookie($formid, 1, 86400); //name formid, value 1, expires in 86400 seconds
}
}
}
?>

tangoforce
05-24-2011, 04:05 PM
So you're trying to limit the number of submissions?

That isn't what you're code is doing. It does vaguely resemble it.. but thats not what you're doing.

How many form submits are allowed? - I'm asking because your first if checks if its 2 or more. Presumably the first is 0 which (as you say) allows 3 submissions (0, 1, 2).

Secondly in your else clause you then set the value of the cookie to 1 so every time the first clause isn't met (which it never will be) you set the cookie to 1 (setcookie($formid, 1, 86400);). Next time the script is called it repeats because again, the $_COOKIE value is 1.

You can't increment a cookie value like this: $_COOKIE[$formid] += 1; All that does is increment the value in the array - which is forgotten as soon as the script stops running (when the browser finishes downloading html).

You're probably looking to do this:
setcookie($formid, $_COOKIE[$formid], 86400);

I've also advised you about the use of the submit in your isset previously. You've still not changed it to the name of another form field and thats going to bring you further trouble.

Chris-2k
05-24-2011, 04:12 PM
I know abt da submit button, i just want to get the code working 1st :-)

So ill change to: setcookie($formid, $_COOKIE[$formid], 86400);

Any other edits?

+10

tangoforce
05-24-2011, 04:34 PM
Not at present but i'm sure you'll bring more errors for us to clear up..

I should start writing a debugging guide.. it's actually very simple to debug php and it makes you a hell of a lot better at programming it.

Chris-2k
05-24-2011, 05:01 PM
its still ignoring it...



<?php
if($_POST['submit'])
{

$formid = $_POST['submitdownloads']; //standard variables are easier to work with

if(isset($_COOKIE[$formid]))
{
if($_COOKIE[$formid] >= 2)
{
echo "Thanks for submitting your downloads, you have now reached the limit";
}
else
{
$_COOKIE[$formid] += 1;
echo "Submitting data...";
setcookie($formid, $_COOKIE[$formid], 86400); //name formid, value 1, expires in 86400 seconds
}
}
}
?>

tangoforce
05-24-2011, 05:16 PM
I'm not replying all the time you're still using $_POST['submit'] in your isset().

I've warned you enough and you still don't take it seriously and now you're still complaining your script is 'ignoring it'.

Chris-2k
05-24-2011, 05:18 PM
Firefox 4

tangoforce
05-24-2011, 05:25 PM
Which explains why you don't care for IE users.. until you start getting people moaning that its not working.

Fix that then i'll resume helping. I've tried being polite about it enough times.

Chris-2k
05-24-2011, 05:42 PM
ok m8 fixed, still ignoring:



<?php
if($_POST['sname'])
{

$formid = $_POST['submitdownloads']; //standard variables are easier to work with

if(isset($_COOKIE[$formid]))
{
if($_COOKIE[$formid] >= 2)
{
echo "Thanks for submitting your downloads, you have now reached the limit";
}
else
{
$_COOKIE[$formid] += 1;
echo "Submitting data...";
setcookie($formid, $_COOKIE[$formid], 86400); //name formid, value 1, expires in 86400 seconds
}
}
}
?>


sname = site name

Chris-2k
05-24-2011, 06:07 PM
ok m8, im gonna go eat n watch. the football, be back in 4 - 5hrs..........

than so far, cya later.

Chris-2k
05-24-2011, 10:35 PM
ok m8 fixed, still ignoring:



<?php
if($_POST['sname'])
{

$formid = $_POST['submitdownloads']; //standard variables are easier to work with

if(isset($_COOKIE[$formid]))
{
if($_COOKIE[$formid] >= 2)
{
echo "Thanks for submitting your downloads, you have now reached the limit";
}
else
{
$_COOKIE[$formid] += 1;
echo "Submitting data...";
setcookie($formid, $_COOKIE[$formid], 86400); //name formid, value 1, expires in 86400 seconds
}
}
}
?>


sname = site name

tangoforce
05-24-2011, 10:47 PM
Can you download TeamViewer please i'll connect to your desktop and take a look.

Once you've got it running PM me your connection details.

Chris-2k
05-24-2011, 11:09 PM
PMed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum