如何在Javascript中使用PHP变量? [英] How to use PHP variable in Javascript?
问题描述
我知道你不能在javascript代码中直接使用PHP变量,但它有办法吗?我需要在javascript中使用这些参数:
I know you can't directly use PHP variables inside javascript code, but is there a way around it? I need to use these parameter's in javascript:
username: '<?php echo $user_id;?>.example.co.uk',
password: 'example',
而不是显示$ user_id变量,输出:资源ID#4.example.co.uk
Instead of showing the $user_id variable, it outputs: "Resource id #4.example.co.uk"
我很新到了javascript所以我发现它非常棘手。
I'm quite new to javascript so I'm finding it pretty tricky.
感谢您的帮助
编辑:我正在服用来自URL的$ user_id变量如下:
I am taking the $user_id variable from the URL like so:
$user_id = mysql_real_escape_string($_GET["user_id"]);
所以它不应该只是来自URL的设定值吗?
so shouldn't it just have the set value from the URL?
推荐答案
资源ID#4 表示你还没有完成mysql查询
Resource id #4 means u have just not complete the mysql query
mysql_query 返回资源ID
你必须使用获取数据while($ row = mysql_fetch_array() )
然后使用
用于SELECT,SHOW,DESCRIBE,EXPLAIN
和其他语句返回
结果集,mysql_query()在成功时返回
资源,或者在
错误时返回FALSE。
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
对于其他类型的SQL语句,
INSERT,UPDATE,DELETE,DROP等,
mysql_query()成功返回TRUE
或错误时返回FALSE。
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
UPDATE
不要使用 mysql_real_escape字符串
获取GET da ta..instead use (int)$ _ GET ['id']
UPDATE
don't use mysql_real_escape string
for GET data..instead use (int)$_GET['id']
如果未找到连接或建立
,则会生成E_WARNING级别错误
If no connection is found or established, an E_WARNING level error is generated
这篇关于如何在Javascript中使用PHP变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!