Page 1 of 1

HELP! PHP running on Page Load

Posted: Wed Oct 13, 2010 9:49 am
by kapi923
Help.

I have created a form to post information to a DB based on the answer the testee choses. The problem is it post the testee's answer to the DB when the page loads before the testee makes their choice. What am I doing wrong? The correct answer is D and 1 should be loaded to the DB but it post the first answer which is A and loads 0 into the DB. HELP??

1) One of the goals for the LGA's Security Awareness Program is:</font></a><br><br>

<!-- A -->
<form name="Answer1a" method="post">
<input type="submit" name="quest1" value="A" onclick="alertIncorrect()"/> To promote security within LGA by ensuring that its employees are knowledgeable of policies and procedures<br>
<?php
//Write to database
$name = $_REQUEST["name1"];
$department = $_REQUEST["department"];
$value = 0;

$link = mssql_connect('MDMSSQL01', '', '');

mssql_select_db('SecurityAwareness', $link);
mssql_query("UPDATE TestAnswers SET Answer1 = '$value'
WHERE name = '$name' and Answer1 IS Null");
?>
</form>

<!-- B -->
<form name="Answer1b" method="post">
<input type="submit" name="quest1" value="B" onclick="alertIncorrect()"/> To inform LGA employees of acceptable devices, systems and software.<br>
<?php
//Write to database
$name = $_REQUEST["name1"];
$department = $_REQUEST["department"];
$value = 0;

$link = mssql_connect('MDMSSQL01', '', '');

mssql_select_db('SecurityAwareness', $link);
mssql_query("UPDATE TestAnswers SET Answer1 = '$value'
WHERE name = '$name' and Answer1 IS Null");
?>
</form>

<!-- C -->
<form name="Answer1c" method="post">
<input type="submit" name="quest1" value="C" onclick="alertInorrect()"/> To ensure proper disclosure of email and company data and inform employees of how to keep data on our network secure.<br>
<?php
//Write to database
$name = $_REQUEST["name1"];
$department = $_REQUEST["department"];
$value = 0;

$link = mssql_connect('MDMSSQL01', '', '');
mssql_select_db('SecurityAwareness', $link);
mssql_query("UPDATE TestAnswers SET Answer1 = '$value'
WHERE name = '$name' and Answer1 IS Null");
?>
</form>

<!-- D -->
<form name="Answer1d" method="post" action="securityawarenessq2.php">
<input type="submit" name="quest1" value="D" onclick="alertCorrect()"/> All of the above.
<?php
//Write to database
$name = $_REQUEST["name1"];
$department = $_REQUEST["department"];
$value = 1;

$link = mssql_connect('MDMSSQL01', '', '');
mssql_select_db('SecurityAwareness', $link);
mssql_query("UPDATE TestAnswers SET Answer1 = '$value'
WHERE name = '$name' and Answer1 IS Null");
?>
</form>

Re: HELP! PHP running on Page Load

Posted: Wed Oct 13, 2010 12:22 pm
by Jonah Bron
You need to change this. Instead of having a dozen forms, one for each answer, you need to create one form with a radio selection box inside. And you should not tell the person he's wrong statically with Javascript. The only thing he has to do to get the right answer is right click > view source.