<?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


Recommended Answers

All 2 Replies

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 for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.