AlphaDaemon AlphaDaemon - 5 months ago 19
Javascript Question

How can I use PHP MySQL with NodeJS and SocketIO

I am in the process of making a chat app. I create accounts, login, select, view and do more already with PHP MySQL. And I am beginning to get into the Instant Messaging side of things.

I am using NodeJS and SocketIO for this and I have got the demo and such running but when attempting to integrate it into my current PHP stack it fails the mysql calls. I believe the problem is the networking but I could be wrong. Some direction or advice would be much appreciated.

User hits index.html > authenticate.js(ajax) > Sessions.php > Redirect to login or load page with data. However the echo data back:

echo "<script type='text/javascript'>
$('#detailsnote').hide();
$('#edituserimage').attr('src','$Image');
$('#editusername').val('$Username');
$('#editfirstname').val('$Firstname');
$('#editlastname').val('$Lastname');
$('#editnickname').val('$Nickname');
$('#editposition').val('$Position');
$('#editmobile').val('$Mobile');
$('#editdob').val('$DOB');
$('#editemail').val('$Email');
$('#userid').val('$UserID');
</script>";


Gets put in a div that handles that data, but instead, it is showing that echo as text.

I could be entirely wrong and can't mix PHP and NODEJS with MYSQL but I thought it would work. So again, any advice is welcome. Even if it is "Re-write the whole thing in NodeJS"

Answer Source

You can't combine php code with node JS code. Node does not understand the echo keyboard.