jquery窗口位置不能在php echo里面工作?

jquery window location is not work inside the php echo statement, is there any wrong in my code?

this is my code:

<?php
include "connection/db_connection.php";
$error=''; 
if(isset($_POST['submit']))

{ 
$sno=$_POST['sno'];
$name=$_POST['name'];
$country=$_POST['s2'];
$username=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['pwfield'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state']; 

$sql2="select email from login_warehouse WHERE email='".$email."' AND sno!='".$sno."'";
$result2=mysql_query($sql2);
if(mysql_fetch_array($result2)>= 1) 
{

    $error= "Entered E-Mail ID Already in Exists!<br/>";
}
else
{
    $sql=mysql_query("update `login_warehouse` set name='".$name."', username='".$username."', password='".$password."', email='".$email."',address='".$address."',city='".$city."',state='".$state."', country='".$country."' where sno='".$sno."'");
    if($sql)
    {
        echo '<script>
        $(window).load(function () {
        window.setTimeout(function () {
        window.location.href = "edit_userprofile.php";
        }, 900)
        }); 
        </script>';
       $error='Admin details updated successfully!';            
  }
else
{

$error="Customer Already Exists";
}       
}
}
?>      

what i wrote wrong in echo statement? or any other way is there to reload the page if the condition is true.

If you really want to use jQuery/javascript , make sure you include jQuery library before Any jQuery code . If your posted code is the Starting code Before HTML , make sure you include js library first.

I would say if you use jquery to redirect , you will need DOM to be loaded (it will take a few seconds), window to be loaded , if you use php header() you will get redirected Instantly.

There is no error in your Javascript. Check where your query is executing successfully.

Why don't you use PHP's header() to redirect the page.

if($sql)
{
   header("location:edit_userprofile.php");

Since you are using jQuery code, you must include the jQuery library file before the jQuery code executes.

You can use PHP header() to redirect to page you want like below:

if($sql)
{
    header("location:edit_userprofile.php");
}
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<?php
include "connection/db_connection.php";
$error=''; 
if(isset($_POST['submit']))

{ 
$sno=$_POST['sno'];
$name=$_POST['name'];
$country=$_POST['s2'];
$username=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['pwfield'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state']; 

$sql2="select email from login_warehouse WHERE email='".$email."' AND     sno!='".$sno."'";
$result2=mysql_query($sql2);
if(mysql_fetch_array($result2)>= 1) 
{

$error= "Entered E-Mail ID Already in Exists!<br/>";
}
else
{
$sql=mysql_query("update `login_warehouse` set name='".$name."', username='".$username."', password='".$password."', email='".$email."',address='".$address."',city='".$city."',state='".$state."', country='".$country."' where sno='".$sno."'");
if($sql)
{
    echo '<script>
    $(window).load(function () {
    window.setTimeout(function () {
    window.location.href = "edit_userprofile.php";
    }, 900)
    }); 
    </script>';
   $error='Admin details updated successfully!';            
  }
else
{

$error="Customer Already Exists";
}       
}
}
?>