0

I don't know why but the script tag is not working, the SELECT query is working but i am not getting the prompt from the javascript. it is not redirecting anywhere only a blank screen is seen

$qry1="SELECT area, aadhar FROM user where username='$user'";
$result1 = $connector->query($qry1);
if($result1){
$row1=mysql_fetch_array($result1);
$userarea= $row1['area'];
$useraadhar=$row1['aadhar'];
}?>
<body>

<script type="text/javascript">
var inputarea=<?php echo $coursename; ?>;
var userarea=<?php echo $userarea; ?>;
var useraadhar=<?php echo $useraadhar;?>'
if(inputarea==userarea){
<?php/
//date
$today = date("Y-m-d");
//Create INSERT query
$qry = "INSERT INTO complain (user,category,regno,course,lecturer,room,details,address,datein) VALUES ('$userid','$category','$reg','$coursename','$lectname','$roomno','$details','$address','$today')";

    //$result = @mysql_query($qry);
$result = $connector->query($qry);
//Check whether difjslk the query was successful or not
if($result) {
$errmsg_arr[] = 'Complain succesfully added, please wait for your response';
    $errflag = true;
    if($errflag) {
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
    session_write_close();
    header("location: _new_complains.php");
    exit();
}


    header("location: _new_complains.php");
    exit();
}else {
    die("Query failed, couldn't add the new record");
    header("location: _new_complains.php");
    exit();
}

?>
}

2
  • 1
    I would start checking the syntax highlighting, something is not right. Commented Jan 2, 2014 at 17:49
  • Can you edit your answer to show us the source code for the entire page? That would help us identify the problems better. Commented Jan 2, 2014 at 18:21

2 Answers 2

1

You are sending data (for example body tag) before header(), therefore PHP creates an error. You just don't see it. Header needs to come before anything is sent to the browser (even a space).

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

3 Comments

if i remove the body tag will it make any difference
php.net/manual/en/function.header.php You cannot use header() after sending data to the browser. Your header() calls MUST be before any HTML. Use javascript to redirect the user, e.g. window.location = "yoururl.com";
Move all the HTML/JS to after the last </php>. If you just want to redirect the user in certain case, you don't need it. Only if the condifion is met (no err) the HTML will be parsed by the server and served to the user. Or do as Dave said and redirect via javascript.
0

You have multiple JS syntax errors:

var inputarea=<?php echo $coursename; ?>;
var userarea=<?php echo $userarea; ?>;
var useraadhar=<?php echo $useraadhar;?>'

Never EVER dump out raw text from PHP into a Javascript context. You're generating code that looks like

var inputarea=foo;
var userarea=bar;
var useradhar=baz';

The data will be seen as undefined variables, and you've got a stray ' in there. All of these errors will KILL the entire <script> block.

Always use json_encode() to dump from PHP->JS:

var inputarea = <?php echo json_encode($coursename); ?>;

This will GUARANTEE that you're producing correct Javascript code. The above line would produce

var inputarea = 'foo';

and be perfectly valid and executable code.

1 Comment

So start debugging. Do a view source and see if you're getting anything. Check your javascript console and look for errors/warnings, etc...

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.