+ 5
Javascript function in PHP
How can I call a javascript function in PHP and execute the function on data that is being retrieved from a database? Any help will be greatly appreciated
8 odpowiedzi
+ 8
JavaScript and PHP are both scripting languages but not much close that they can handle each other function though there are many ways to do simple task with PHP and js like:
$sql = "INSERT INTO test_db (username,password) VALUES ('name','pass')";
if (mysqli_query($sql)) {
echo "<script>";
echo "alert('Query succes')";
echo "</script>";
}else{
echo "<script>";
echo "alert('Query failed')";
echo "</script>";
}
like this method i think we can call js function inside php
echo "<script>";
echo "test()";
echo "</script>";
USING AJAX can be helpful too
+ 6
Wendy Seijas Thanks so much
+ 5
PHP would not call a JavaScript function.
They are executed in different places. PHP run on server, whereas JavaScript run on client pc.
+ 5
using JSON is the best solution.. i guess
+ 5
Andrew Ting Mai Zau Thanks
+ 4
Shudarshan Rai 👑 Thanks
I will try that method
+ 4
for your solution, the following link is a good one...try it..
http://blog.oskoui-oskoui.com/?p=1262
+ 3
PHP only parsing JavaScript code, it never can execute it.