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

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



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

     <script type="text/javascript">



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

                    data :'username=' +username,
                    success: function(ajax){




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

    @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());

                        echo"PASSWORD DONT MATCH";



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


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.

commented: yes +14
Member Avatar

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