2011-08-19 95 views
2

我对PHP很新,只​​是想学习,但似乎无法摆脱大门,所以请......不要笑:)。我试图创建一个非常基本的表单,这将允许我从mysql获取信息并将信息发布到html页面。下面是我到目前为止有:如何将表格数据插入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 \测试\模块\ mod_php的\ mod_php的.PHP(36):的eval()“上线d码8

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 [email protected] 
* @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

所以,这是进入一个基于的Joomla,网站,或者它应该只是你的标准网页? – Guttsy

+3

你的'过了一会儿失踪)($行= mysql_fetch_array($查询):' – jackJoe

+1

如果你不这样做“PHP评价”你刚刚得到的文件的原始内容有没有这样的事,作为一个。 PHP脚本 - 只有正好包含php代码块的文本文件,如果你在浏览器中做了一个view-source,你会看到原始的PHP + html代码 –

回答

0

我认为你缺少“;”在连接代码行和查询结束时。请检查并让我知道它是否适合您。

+0

试过没有运气。 – lary

+0

接近一点,关闭,现在数据显示,但为什么不插入int语句?谢谢!!! – lary

0

这可能是因为你的说法是任何PHP标记外,因而没有得到评估。

从你最后的评论我猜你得到一些数据,显示在页面上,但[名]和[宠物]字段没有得到与语句中的实际值替换。

请更换此...

<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!