0

I have this form that is asking for a security question and answer and upon submit the data is entered into my SQL DB but for some reason when I run the form and try to print the displayed data to make sure it got entered correctly the data is blank so I check the SQL db and there was a new entry but it was all blank.

I'm trying to figure out why the form is not entering any data into the SQL DB.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<form method="post" id="myForm" name="input" action="submitSQL.php">

        Security Question: <input type="text" id="sQuestion" ></br>
        Security Question Answer: <input type="text" id="sqAnswer" ></br>


        </br>
        <input type="submit">

        </form>

</body>
</html>

PHP File

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<?php

$sQuestion = filter_input(INPUT_POST, 'sQuestion');
$sqAnswer = filter_input(INPUT_POST, 'sqAnswer');

$conn = mysql_connect("localhost","root","")or die (mysql_error());

mysql_select_db("assignment_3", $conn);

$insert = "insert into securityquestiontable (securityQuestion, securityAnswer)     values('$sqAnswer', '$sQuestion')";

$result = mysql_query($insert, $conn) or die (mysql_error());

print "<table border=1>
<tr><td>Security Question:</td><td> '$sQuestion'</td></tr></br>
<tr><td>Security Question Answer:</td> <td> '$sqAnswer'</td></tr></br>

</table>";

?>

</body>
</html>
user2880722
  • 37
  • 1
  • 2
  • 7
  • 1
    This calls for basic debugging. Does `$sQuestion` ever contain a value? (the problem here is that you're not giving your form elements a `name` attribute, though) – Pekka Nov 18 '13 at 01:19
  • The sql-server tag refers to a specific RDBMS made by Microsoft, not mysql which you're using. Your mysql code is also [vulnerable to injection](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) and [using an obsolete API](http://php.net/manual/en/mysqlinfo.api.choosing.php). And finally, when PHP generates a blank page instead of doing something, you need to [enable error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php). – Dan Nov 18 '13 at 01:22

1 Answers1

0

You haven't specified name attributes for your fields.

This:

    Security Question: <input type="text" id="sQuestion" ></br>
    Security Question Answer: <input type="text" id="sqAnswer" ></br>

Should be this:

    Security Question: <input type="text" id="sQuestion" name="sQuestion"></br>
    Security Question Answer: <input type="text" id="sqAnswer" name="sqAnswer"></br>
Darren
  • 13,050
  • 4
  • 41
  • 79