JAVA & PHP VARIABLES ?

  • Thread starter Thread starter exxos
  • Start date Start date
E

exxos

Guest
I can get PHP variables in JAVA by just using the PHP echo $variable which works fine.. however I have run into a snag with a more complex line..
.
<?PHP
$user='exxos';
$data = mysql_query("Select * from x7chat2_users where username='$user' ") or die(mysql_error());
$info = mysql_fetch_array( $data );
echo $info['rank'];
?>

the above code works fine in PHP, but the problem is if I did something like..

alert ("< PHP CODE FROM ABOVE>");

the problem is I end up with double quotation marks, the first set is the actual java quote marks, then the second set in the mysql_query line, so Java gets confused...

I have used the ' marks to overcome a lot of the problem, but I am stuck now as I cant pass the PHP value to a JAVA value as I can't use anymore quotation marks as they are already used in the PHP code.

The line would read something like

ALERT (" <?PHP $user='exxos'; $data = mysql_query("Select * from x7chat2_users where username='$user' ") or ie(mysql_error()); $info = mysql_fetch_array( $data ); echo $info['rank'];?> ");

So it would pop up with Java the $info['rank'] variable from PHP after it has read the value from the server (done elsewhere).

I may be going about this all the wrong way :-s
thanks, I did try using the slash thing but I still cant get it to work, I copied your edited line in directly and it just says...

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/future/public_html/x7chat2/sources/frame.php on line 477

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/future/public_html/x7chat2/sources/frame.php on line 477
as the final line, which may or may not help..

it should look like this

ALERT (" <?PHP $data = mysql_query(\"Select * from x7chat2_users where username='" + dataSubArray2[x2] + "'\") ); $info = mysql_fetch_array( $data ); echo $info['rank'];?> ");


now, $user has been removed from the PHP code, and dataSubArray2[x2] is a JS variable.. I tried to break out of the PHP line then add in the JS variable then break back into the PHP line, I think it is correct, but still get errors :-(

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/future/public_html/x7chat2/sources/frame.php on line 477

Parse error: syntax error, unexpected '[' in /home/future/public_html/x7chat2/sources/frame.php on line 477
-----------------------------

it does not liek the slash thing, final tweak...

var userthingy = dataSubArray2[x2];
alert (" <?PHP $data = mysql_query(\"Select * from x7chat2_users where username='" + userthingy + "'\") ); $info = mysql_fetch_array( $data ); echo $info['rank'];?> ") ;


Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/future/public_html/x7chat2/sources/frame.php on line 479

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/future/public_html/x7chat2/sources/frame.php on line 479
 
Back
Top