HELP! PHP running on Page Load
Posted: Wed Oct 13, 2010 9:49 am
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>
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>