0

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);
}

 ?>
7
  • 1
    None of this code is changing action <form> action. I'm guessing your 'unknown' is coming from javascript, and you're running an old IE version that says 'unknown' instead of 'undefined' Commented May 11, 2014 at 22:54
  • Can you clarify what you mean when you say changing action <form> action? And yes that's correct about the older ie. Commented May 11, 2014 at 22:59
  • You have some javascript that's updating your <form action=""> to append a variable. Look for some code somewhere that concatenates a path to make the action. That js code will have a variable you're concatenating which isn't set, so it'll create your path with 'unknown' in it. Commented May 11, 2014 at 23:03
  • I'm not using action="" (should I be?). My form opens: <form method="post", has all of the content and a submit button then closes. Commented May 11, 2014 at 23:18
  • 1
    action tells the javascript where to send the form information to be processed. If there is no action defined, there's nothing else for it do, basically. Commented May 11, 2014 at 23:30

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.