0

Hello folks

I am trying to get a PHP variable to pass values to a sample javascript but nothing shows up if I tried to echo the result.

I tried passing regular strings as arguments and those worked fine. It just doesn't seem to be working if I tried to pass PHP variables as arguments.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>AES (Rijndael) Encryption Test in JavaScript</title>

<script type="text/javascript" src="Decrypt.js"></script>


</head>

<body>
<?php
    mysql_connect("localhost","root","");
    mysql_select_db("encryption") or die(mysql_error());
    $userId = $_POST['userId'];


        if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == ""))
        {

            $query = mysql_query("select * from employee_details where id = '$userId'");
                if($row=mysql_fetch_assoc($query))
                    {
                        echo '<tr>';
                        foreach($row as $value)
                        echo '<td>'.$value.'</td>';
                        echo '</tr>';
                    }

                else { echo "No rows returned"; }}
        else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key']))
            {

               $columname = "ciphertext";
               $tablename = "employee_details";
               
               

                    function getField($field, $tbl_name, $condition)
                {
                    
                    $result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition);

                     return @mysql_result($result, 0);
                }

                    $myValue = getField($columname,$tablename,$userId);

                    echo "Ciphertext = $myValue";
                    echo "<br>";
                    //doDecryption();

            }
            echo '<script type="text/javascript">
    doDecryption("<?php $myValue; ?>");
    </script>';
    echo "whats happening";
?>
</body>
</html>

The JS file

function doDecryption(param)
{
    document.write(param);
    document.write("Programming change");
}

Thanks in advance. Any help much appreciated!!!!

3
Contributors
2
Replies
6
Views
6 Years
Discussion Span
Last Post by Dragonbaki
-2

Look closely as the line:

echo '<script type="text/javascript">
doDecryption("<?php $myValue; ?>");
</script>';

See anything wrong?
I would suggest not outputting HTML code in an echo statement, but it is entirely up to you.

If you still don't see the problem, hint ' != "

Votes + Comments
Didn't answer the question
-1

Try to do like this... You will get it...

echo "<script type='text/javascript'>
doDecryption('<?php $myValue; ?>');
</script>";

Edited by Dragonbaki: n/a

Votes + Comments
That will acheive absolutely nothing
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.