php+mysql 最簡單的留言板

來源:互聯網
上載者:User

標籤:code   定位   not   article   簡單   resource   header   border   har   

學完了記得動手操作。

測試地址(未過濾)

<html><body><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><form method = "post" action = "post.php">歡迎來到我的留言板!

<br>name:<input type = "text" name = "name"><br>email:<input type = "text" name = "email"><br>content:<br><textarea rows="10" cols="20" name="content"></textarea><input type = "submit"></form></body></html>


<?php header("Content-type: text/html; charset=utf-8"); $con = mysql_connect("***","***","***");if (!$con)  {  die('Could not connect: ' . 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['name'] ;$email =  $_POST['email'];$content = $_POST['content'];$sql1 = "INSERT INTO message(name,email,content)VALUES( '$name', '$email','$content')";mysql_query($sql1,$con);echo "<table border='1'><tr><th>id</th><th>name</th><th>email</th><th>content</th></tr>";$result = mysql_query("SELECT * FROM message");while($row = mysql_fetch_array($result))  {  echo "<tr>";  echo "<td>" . $row['id'] . "</td>";  echo "<td>" . $row['name'] . "</td>";  echo "<td>" . $row['email'] . "</td>";  echo "<td>" . $row['content'] . "</td>";  echo "</tr>";  }echo "</table>";mysql_close($con);?>

中途遇到一個bug

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

定位到該函數。$result的值不是有效。

懷疑是資料庫沒有串連成功。

推斷一下$result。輸出mysql_error();

發現是沒有資料庫選擇。

原來放在本地能夠啟動並執行,原來放到網站上資料庫名稱寫成表單名稱了。

蠢哭。

= =!!

!

php+mysql 最簡單的留言板

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.