Home >Backend Development >PHP Tutorial >php+mysql 最简单的留言板_PHP教程

php+mysql 最简单的留言板_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:44:461059browse

php+mysql 最简单的留言板

学完了记得动手操作。

 





<!--?php 
header(Content-type: text/html; charset=utf-8); 
$con = mysql_connect(***,***,***);
if (!$con)
  {
  die(&#39;Could not connect: &#39; . mysql_error());
  }
//connect table
  mysql_query(SET NAMES utf8);
 mysql_select_db(message,$con);

$sql = CREATE TABLE message(
id int NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
name varchar(15),
email varchar(15),
content varchar(100)
 );
//mysql_query($sql,$con);

$name =  $_POST[&#39;name&#39;] ;
$email =  $_POST[&#39;email&#39;];
$content = $_POST[&#39;content&#39;];

$sql1 = INSERT INTO message(name,email,content)
VALUES( &#39;$name&#39;, &#39;$email&#39;,&#39;$content&#39;);

mysql_query($sql1,$con);

echo <table border=&#39;1&#39;-->

id
name
email
content
;

$result = mysql_query(SELECT * FROM message);

while($row = mysql_fetch_array($result))
  {
  echo ;
  echo  . $row[&#39;id&#39;] . ;
  echo  . $row[&#39;name&#39;] . ;
  echo  . $row[&#39;email&#39;] . ;
  echo  . $row[&#39;content&#39;] . ;
  echo ;
  }
echo ;

mysql_close($con);
?>

中途遇到一个bug

 

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

定位到该函数,$result的值不是有效的。

怀疑是数据库没有连接成功。

判断一下$result,输出mysql_error();

发现是没有数据库选择。

原来放在本地可以执行的,原来放到网站上数据库名称写成表单名称了。

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1047180.htmlTechArticlephp+mysql 最简单的留言板 学完了记得动手操作。 idnameemailcontent;$result = mysql_query(SELECT * FROM message);while($row = mysql_fetch_array($result)) { echo ; ech...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn