0

<?php session_start(); include 'forms.php'; include 'config.php'; include 'lib.php'; ?>

<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<link href="css/main.css" rel="stylesheet" />

</head>

<body>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script> 

     <script type="text/javascript">

        $(document).ready(function(){



            $("#check").click(function(){

                var username = ("<?= $username ?>");

                $.ajax({
                    url:"ajax.php",
                    data :'username=' +username,
                    success: function(ajax){
                        $("#ajax").append(ajax);


                    }
                });
                })
            });
     </script>

</body>

</html>
<?php

    if ($_SESSION['username'])
        echo "welcome, ".$_SESSION['username']."!<br><a href='logout.php'>LOGOUT</a>";
    else 
        die("You must be logged in");


    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $rpassword  = $_GET["rpassword"];
    $password  =$_GET["password"];
    $firstname =$_GET["firstname"];
    $secondname =$_GET["secondname"];
    $username =$_GET["username"];

    if (isset ($_GET['username'])) 
    {

                if($password==$rpassword){  //checks if passwords match             


                        $query = "INSERT INTO users VALUES (NULL,'$firstname','$secondname','$username','$password')";
                        mysql_query($query) or die("$query failed with error ".mysql_error());
                    }


                    else
                        echo"PASSWORD DONT MATCH";

    } 

        loginform();
        get();
?>

need to transfer php variable $username into javascript varible var username
for some reason the above "var username = ("<?= $username ?>");" line dont work
How ever if i replaced ("<?= $username ?>") with "username" it works please helk

thnks

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by diafol
1

Could you try running the not-working code, and use the browsers source-viewer to check what was echoed to JavaScript?

also, is this the chronological order of the file? because it seems you are defining $username AFTER using it. which should result in an error message.

Votes + Comments
yes
0

agree with phoenix - you need to set username before placing it in the js code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.