Reputation: 823
I'm writing a script where the user selects an option from a box then they click submit and their choice is written to a MySQL database. Whenever I try to click submit, however, the url changes from (for example: www.stackoverflow.com/questions to www.stackoverflow.com/questions/unknown). I've been searching around for hours and can't seem to figure out why this is happening. Does anyone have any suggestions as to what could be causing this? This is the script that is supposed to run when someone clicks the submit button.
if( $_POST )
{
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
$q4 = $_POST['q4'];
$q5 = $_POST['q5'];
$q6 = $_POST['q6'];
$q7 = $_POST['q7'];
$q7 = $_POST['q7'];
$q8 = $_POST['q8'];
$qf1 = $_POST['qf1'];
$qf2 = $_POST['qf2'];
$qf3 = $_POST['qf3'];
$qf4 = $_POST['qf4'];
$s1 = $_POST['s1'];
$s2 = $_POST['s2'];
$final = $_POST['final'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$q1 = mysql_real_escape_string($q1);
$q2 = mysql_real_escape_string($q2);
$q3 = mysql_real_escape_string($q3);
$q4 = mysql_real_escape_string($q4);
$q5 = mysql_real_escape_string($q5);
$q6 = mysql_real_escape_string($q6);
$q7 = mysql_real_escape_string($q7);
$q8 = mysql_real_escape_string($q8);
$qf1 = mysql_real_escape_string($qf1);
$qf2 = mysql_real_escape_string($qf2);
$qf3 = mysql_real_escape_string($qf3);
$qf4 = mysql_real_escape_string($qf4);
$s1 = mysql_real_escape_string($s1);
$s2 = mysql_real_escape_string($s2);
$final = mysql_real_escape_string($final);
$fname = mysql_real_escape_string($fname);
$lname = mysql_real_escape_string($lname);
$query = "
INSERT INTO `db_name`.`table_name` (`qualifier_1`, `qualifier_2`, `qualifier_3`, `qualifier_4`, `qualifier_5`, `qualifier_6`, `qualifier_7`, `qualifier_8`, `quarter_1`, `quarter_2`, `quarter_3`, `quarter_4`, `semi_1`, `semi_2`, 'final', 'first_name', 'last_name', 'TimeDate') VALUES ('$q1', '$q2', '$q3', '$q4', '$q5', '$q6', '$q7', '$q8', '$qf1', '$qf2', '$qf3', '$qf4', '$s1', '$s2', '$final', '$fname', '$lname', CURRENT_TIMESTAMP);";
mysql_query($query);
echo "<h2>Thank you for your Submission!</h2>";
mysql_close($con);
}
?>
Upvotes: 0
Views: 47
Reputation: 6908
As you're running on an older IE version, what you're seeing isn't related to PHP at all, but JavaScript. In JavaScript, if you concatenate an undefined variable, the word 'undefined' is literally concatenated, e.g.:
var mystring = "foo" + bar;
Will, if bar is undefined, set mystring to "fooundefined". On IE7 and older, it will instead be "foounknown".
There must be JavaScript setting your form's action, so this is all happening outside the code you posted. Check MDN ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form ) for details on using the form element. Either the 'action' on your is being set in js, or the 'formaction' of the button is being set. Check that code, and you will see some concatenation of an undefined variable causing this.
Upvotes: 3