0

I have a .php page that calls itself via a form multiple times. The user has 9 input choices that are represented by images. Let's say the .php file is called quiz.php:

<?php

...blah blah php session start variable stuff

$client_answer = $_POST['input_from_test_1'] ;
$true_answer = $_SESSION["1-2-2_true_answer"];
if($client_answer == $true_answer)
{
$feedbackJudgement=1;
}
else
{
$feedbackJudgement=0;
}

 $randomHandType = rand(1,13);
 if ($randomHandType >= 10)
{
$randomHandType = 1;
}
 $true_answer = $randomHandType;


print"
<form  method='post' action='quiz.php'>";
//the following three rows are the 9 feedback buttons the client
// has available to him.  A keypad of hand types.

//row 1
 print"


<div style='position: absolute; left: 400px; top: 440px;'>
<input type='image'  value='1' name='input_from_test_1' src='1_button.png'>
</div> 

<div style='position: absolute; left: 565px; top: 440px;'>
<input type='image'  value='2' name='input_from_test_1' src='2_button.png'>
</div> 

<div style='position: absolute; left: 730px; top: 440px;'>
<input type='image'  value='3' name='input_from_test_1' src='3_button.png'>
</div> 
";

//row 2
print "
<div style='position: absolute; left: 400px; top: 520px;'>
<input type='image'  value='4' name='input_from_test_1' src='4_button.png'>
</div> 

<div style='position: absolute; left: 565px; top: 520px;'>
<input type='image'  value='5' name='input_from_test_1' src='5_button.png'>
</div> 

<div style='position: absolute; left: 730px; top: 520px;'>
<input type='image'  value='6' name='input_from_test_1' src='6_button.png'>
</div> 
";

//row 3
print "
<div style='position: absolute; left: 400px; top: 600px;'>
<input type='image'  value='7' name='input_from_test_1' src='7_button.png'>
</div> 

<div style='position: absolute; left: 565px; top: 600px;'>
<input type='image'  value='8' name='input_from_test_1' src='8_button.png'>
</div> 

<div style='position: absolute; left: 730px; top: 600px;'>
<input type='image'  value='9' name='input_from_test_1' src='9_button.png'>
</div> ";



print "</form>";

this is just part of the code as the complete .php is quite long and complex.

The script works on Google Chrome but only for the first ~100 submitals. After that I get a "No data received" "Error code: ERR_EMPTY_RESPONSE".

With Firefox I get a similar error after many inputs "The connection was reset". Is this just some error I can't avoid as the server will time out after so many form submitals?

When I get this error I have to wait ~30 seconds and refresh and then it sends a NULL value instead of the user input.

What are some alternatives I can use to do this differently. Is it okay to use

<input type='image'  value='9' name='input_from_test_1' src='9_button.png'>

as a submit button?

Thank you

Maz I
  • 3,664
  • 2
  • 23
  • 38
  • tag cannot be used to submit a form. If your form is indeed getting submitted, check the onclick() event of your inputs, it must be getting submitted from there using javascript. – Prahlad Yeri Dec 10 '13 at 05:33
  • @PrahladYeri [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input) says it's a _graphical submit button._ – Barmar Dec 10 '13 at 05:35
  • What are `$feedbackJudgement` and `$randomHandType` used for? It may have something to do with that. – Barmar Dec 10 '13 at 05:37
  • the feedback judgement and randomhandtype are unrelated. Yes I am using the to act as a kind of radio button that submits a value on click. This works fine on chrome. Should I be using javascript to aid this with the onclick() function? I have avoided using javascript as it can be disabled and I want my quiz to work with as many browsers as possible. – user3085488 Dec 10 '13 at 05:43
  • My main fear is I don't understand why this script causes the server to crap out after around ~100 submits. It times out and sends null data instead. Then it works fine for another ~100 submits. Are html forms and PHP post not meant to be used on this high of frequency? Should I be using websockets instead. We are talking about one submit every 3 seconds. Here is an example of a quiz in debug mode so you can see how it works from the users side. http://saltpoker.com/training/unit1/lesson2/u1s2ex02.php – user3085488 Dec 10 '13 at 05:47

1 Answers1

0

An <input type="image"> type of tag can only be used to submit a form, and not the value of the input tag itself. However, this behavior is not consistent across browsers, so it might work in some situations.

See this SO link for reference.

So, try a normal <input type="submit"> tag and test your scenario.

Community
  • 1
  • 1
Prahlad Yeri
  • 3,567
  • 4
  • 25
  • 55
  • Just so that we are on the same page do you mean that I should be doing this: Or Do you mean just make a standard 4 drop down or radio button HTML form with a stand-alone submit button: thanks – user3085488 Dec 10 '13 at 06:03
  • Also, I don't see any need to adjust your backend code since you can have multiple submit buttons with the same name attribute. The value of the one getting clicked will be passed: http://stackoverflow.com/questions/572229/html-forms-how-do-i-add-multiple-buttons-that-pass-different-values – Prahlad Yeri Dec 10 '13 at 06:25
  • Okay when I use the type='submit' it works in both firefox and chrome. However now I am stuck with the ugly default numbered buttons instead of my beautiful images – user3085488 Dec 10 '13 at 09:19
  • Also I am still getting the issue every so many submits "Unable to load the webpage because the server sent no data. Reload this webpage. Press the reload button to resubmit the data needed to load the page. Error code: ERR_EMPTY_RESPONSE" Is there a better method I should be using to send the users data from the front end to the server side? such as posting to a session variable instead of posting directly to the php page. Does anyone have any familiarity with this type of error were a server will time out on a users form submital? – user3085488 Dec 10 '13 at 09:25
  • For the "server sent no data" error, call set_time_limit(0) somewhere at the beginning of your php script to disable script timeouts. See this link: http://stackoverflow.com/questions/14124490/no-data-received-error-when-i-have-a-mysql-query-in-while-loop – Prahlad Yeri Dec 10 '13 at 10:24
  • To improve the look and feel of your button, apply CSS attributes or use a
    tag instead. However, if you use
    , you will have to handle onclick() and submit the form yourself using javascript. See this link for more information: http://stackoverflow.com/questions/2616775/putting-images-inside-a-button-element-html-css
    – Prahlad Yeri Dec 10 '13 at 10:26