开发者

jQuery .post won't read PHP include

开发者 https://www.devze.com 2023-03-30 15:10 出处:网络
I built my website from bunch of php include files that work like a template. When I change something in one file whole website changes.

I built my website from bunch of php include files that work like a template. When I change something in one file whole website changes.

When I click on a radio button, ajax should activate and it should try to communicate with the other php file which should connect to the database and to send information back to the original page, but it can't connect to the database, since that file contains the php include function, and it would only work if I'd put content of that include file manually there. but it won't work if it put it like this

include("includes/connect.php");

and if I manually paste content into that file like this it will work

$connect = mysql_connect("开发者_开发百科localhost","root","");
mysql_select_db("demo") or mysql_error();

is there a way to make it work with include function?


You've forgot that include has nothing to do with client, javascript, post. You're probably including file from wrong folder. Try to change

include("includes/connect.php");

to

include(dirname(__FILE__)."/includes/connect.php");

and make sure that includes/connect.php exists


I think you should use absolute path instead of relative path. Try to change

include("includes/connect.php");

on

include(__DIR__ . "/includes/connect.php");

You should add /../../ near includes for getting right way. If you use PHP5.2 instead of __DIR__ use dirname(__FILE__');

0

精彩评论

暂无评论...
验证码 换一张
取 消