html - 自學(xué)php 遇到代碼不執(zhí)行直接在網(wǎng)頁(yè)上顯示 望各位大神不吝賜教
問(wèn)題描述
<html><head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <title>新聞客戶端</title></head><body><center>國(guó)際新聞</center><table width='100%'><tr><td align='right'><a href='http://m.cgvv.com.cn/wenda/add.php?fl=3'>添加國(guó)際新聞</a></td></tr></table><hr><table border='1' width='70%'><tr><td align='center'><a href='http://m.cgvv.com.cn/wenda/index.php'>新聞</a></td><td align='center'><a href='http://m.cgvv.com.cn/wenda/guonei.php'>國(guó)內(nèi)</a></td><td align='center'><a href='http://m.cgvv.com.cn/wenda/guoji.php'>國(guó)際</a></td><td align='center'><a href='http://m.cgvv.com.cn/wenda/shehui.php'>社會(huì)</a></td><td align='center'><a href='http://m.cgvv.com.cn/wenda/gongyi.php'>公益</a></td></tr></table><?$conn=mysqli_connect(’127.0.0.1’, ’root’, ’459354wj’, ’news’);if(!$conn){ echo '連接數(shù)據(jù)庫(kù)失敗';} echo '連接數(shù)據(jù)庫(kù)成功';$sql='set names utf8';$rs=mysqli_query($conn,$sql); $sql='select * from t_news where id=3'; $rs=mysqli_query($conn,$sql); if(!$rs) {mysqli_close($conn);echo '數(shù)據(jù)庫(kù)查詢失敗'; } echo '數(shù)據(jù)庫(kù)查詢成功'; $recordCount=mysqli_num_rows($rs);if($recordCount>0){ echo '<table align=’center’ width=’70%’>'; while($row=mysql_fetch_assoc($rs)) {$id=$row[’id’];$title=$row[’title’];$subtitle=$row[’subtitle’];$picture=$row[’picture’];$content=$row[’content’];$author=$row[’author’];echo '<tr><td align=’left’>';echo $row[’picture’];echo '</td>';echo '<td align=’left’ colspan=’4’ ><b>';echo $row[’title’];echo '</b><br>';echo $row[’subtitle’];echo '<br>';echo $row[’author’];echo '</td>'; echo '</tr>'; } echo '</table>';} mysqli_close($conn);?></body></html>
問(wèn)題貌似出在 $recordCount=mysqli_num_rows($rs); 這行 但是實(shí)在搞不懂有什么問(wèn)題 網(wǎng)頁(yè)執(zhí)行后只顯示一半另一半 直接把代碼輸出了 執(zhí)行效果是這樣的
問(wèn)題解答
回答1:<? 改為 <?php
回答2:你應(yīng)該把文件后綴換成.php而不是.html
回答3:無(wú)論用何種方式,你都需要讓 php 來(lái)解釋你的頁(yè)面,如果該頁(yè)面沒(méi)有被 php 處理,那只會(huì)把代碼當(dāng)純文本輸出。
所以,最好能告知你使用的 Web Server,和你的配置,這更便于提供建議。
回答4:你怎么打開(kāi)的網(wǎng)頁(yè) 不會(huì)是直接打開(kāi)的吧 得敲網(wǎng)址訪問(wèn)web服務(wù)器那么訪問(wèn)
回答5:php標(biāo)簽寫(xiě)成標(biāo)準(zhǔn)形式 <?php ?> 文件名稱后綴 .php 最后如果你沒(méi)有在windows配置過(guò)你php的環(huán)境變量和apache的環(huán)境變量。最好將文件放在wamp當(dāng)中的www文件夾當(dāng)中,然后在通過(guò)localhost去訪問(wèn)。
回答6:首先確認(rèn)你連接至數(shù)據(jù)庫(kù),從代碼的Log來(lái)看,連接成功應(yīng)該會(huì)輸出:'連接數(shù)據(jù)庫(kù)成功',壓根兒沒(méi)走到這步。
回答7:首先,你看一下你這個(gè)文件的后綴名是什么,文件含有php代碼,后綴名必須是要php才可以解析。還有你文件頭應(yīng)該是<?php才可以
回答8:寫(xiě)PHP程序之前要配置apache 或別的服務(wù)器,不然php代碼無(wú)法被解析
相關(guān)文章:
1. 注冊(cè)賬戶文字不能左右分離2. html - vue項(xiàng)目中用到了elementUI問(wèn)題3. 對(duì)mysql某個(gè)字段監(jiān)控的功能4. javascript - table列過(guò)多,有什么插件可以提供列排序和選擇顯示列的功能5. JavaScript事件6. python - 使用readlines()方法讀取文件內(nèi)容后,再用for循環(huán)遍歷文件與變量匹配時(shí)出現(xiàn)疑難?7. showpassword里的this 是什么意思?代表哪個(gè)元素8. html5 - ElementUI table中el-table-column怎么設(shè)置百分比顯示。9. python - 為什么正常輸出中文沒(méi)有亂碼,zip函數(shù)之后出現(xiàn)中文編程unicode編碼的問(wèn)題,我是遍歷輸出的啊。10. javascript - ES6標(biāo)準(zhǔn)入門(mén)中l(wèi)et命令提到的for循環(huán)打印i是10,如果不用let怎么替換?
