我对php很新,只是想学习,但似乎无法走出大门,所以请......不要笑:)。我正在尝试创建一个非常基本的表单,让我从mysql中获取信息并将信息发布到html页面。这是我到目前为止所得到的:
<?PHP
//connect to the server
$connect = mysql_connect("localhost","root","")
///connect to the database
mysql_select_db("test")
//query the database
$query = mysql_query("SELECT * FROM mary WHERE name = 'mary' ")
//fetch the results / convert the results into an array
WHILE($rows = mysql_fetch_array($query):
$name = $rows['name'];
$pet = $rows['pet'];
$email = $rows['email'];
echo "$name<br>$pet<br>;$email";
endwhile
?>
<html>
[name] had a little [pet]. Her fleece was white as snow. Everywhere [name] went, the [pet] was sure to follow.
</html>
我一直收到如下错误:
解析错误:D:\ wamp \ www \ test \ modules \ mod_php \ mod_php.php(36)中的解析错误:第8行的eval()代码
OR(如果我不要求php评估)
$pet
;$email"; endwhile ?> [name] had a little [pet]. Her fleece was white as snow. Everywhere [name] went, the [pet] was sure to follow.
我正在使用的php模块文件如下:
<?php
/*
* mod_html allows inclusion of HTML/JS/CSS and now PHP, in Joomla/Mambo Modules
* @copyright (c) Copyright: Fiji Web Design, www.fijiwebdesign.com.
* @author gabe@fijiwebdesign.com
* @date June 17, 2008
* @package Joomla1.5
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// mod_php version
$ver = '1.0.0.Alpha1-J1.5';
// get module parameters
$php = $params->get( 'php' );
$eval_php = $params->get( 'eval_php' );
$discovery = $params->get( 'discovery' );
// remove annoying <br /> tags from module parameter
$php = str_replace('<br />', '', $php);
// show that site uses mod_php
$debug = $discovery ? JRequest::getVar('debug') : false;
if ($discovery) {
echo "\r\n<!-- /mod_php version $ver (c) www.fijiwebdesign.com -->\r\n";
}
if ($debug == 'mod_php') {
echo '<div style="border:1px solid red;padding:6px;">';
echo '<div style="color:red;font-weight:bold;">Mod PHP</div>';
}
// evaluate the PHP code
if ($eval_php) {
eval("\r\n?>\r\n ".$php."\r\n<?php\r\n");
} else {
echo $php;
}
// end show site uses mod_php
if ($debug == 'mod_php') {
echo '</div>';
}
if ($discovery) {
echo "\r\n<!-- mod_php version $ver/ -->\r\n";
}
?>
任何人都可以通过harikari帮助新手吗?感谢!!!
答案 0 :(得分:1)
我已在以下链接上传了代码。
http://monalisawebstore.in/test.txt
查看屏幕截图中的结果: -
http://screencast.com/t/ZbDkc5DqMg
如果它适合您,请告诉我。
答案 1 :(得分:0)
我认为你错过了';'在连接代码行和查询结束时。请检查并告诉我它是否适合您。
答案 2 :(得分:0)
这可能是因为你的语句不在任何PHP标记之内,因此没有得到评估。
从您上一次评论中我猜您正在获取一些要在页面上显示的数据,但[name]和[pet]字段不会被语句中的实际值替换。
请替换此......
<html>
[name] had a little [pet]. Her fleece was white as snow. Everywhere [name] went, the [pet] was sure to follow.
</html>
用这个:
<html>
<?php echo "$name had a little $pet. Her fleece was white as snow. Everywhere $name went, the $pet was sure to follow."; ?>
</html>
让我知道它是怎么回事。喜欢学习PHP!