留言板的mysql+php的問題


資料庫建立
<?php
header("Content-Type: text/html; charset=utf-8");
$link=mysql_connect("localhost","root","") or die("連接失敗");
if(mysql_select_db("db1")) {
mysql_query("DROP TABLE IF EXISTS tb2");
$sqlstr="create table tb2(message varchar(10)) charset=utf8";
mysql_query($sqlstr) or die("資料表建立失敗");
echo "資料表重新建立成功";
}
?>
資料庫建立

留言跟功能
<?php header("Content-Type:text/html; charset=utf-8"); ?>
<html>
<head>
<title>不負責任留言板</title>
</head>
<body>
<form method="POST" action="message.php">
<h2><strong>盡情留言吧!!</strong></h2>
<p><textarea name="message" rows="8" cols="52"></textarea></p>
<p><input type="submit" value="送出留言"> <input type="reset" value="清除留言"></p>
</form>
<?php
$link=mysql_connect("localhost","root","") or die("連接失敗");
mysql_select_db("db1");
mysql_query("SET NAMES utf8");
$message=$_POST["message"];
if (!empty($message)){
$sqlStr="insert into tb2 (message) ";
$sqlStr.="values('$message')";
echo $sqlStr."<br>";
mysql_query($sqlStr) or die("寫入失敗");
echo "留言寫入成功<hr>";
}else{
echo "請輸入留言內容<hr>";
}
$q=mysql_query('select * from tb2');
$c=1;
while($row=mysql_fetch_row($q)){
foreach ($row as $i){
echo $c++.". ".$i." ";
}
echo "<br>";
}
?>
</body>
</html>
php
建立資料表出現這個問題:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\fish.php on line 3
網頁會出現這個問題:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\message.php on line 13
Notice: Undefined index: message in C:\wamp64\www\message.php on line 16
網頁我輸入資料之後這個訊息會消失:
Notice: Undefined index: message in C:\wamp64\www\message.php on line 16
還是新手希望可以知道這個問題在哪裡
Sign In or Register to comment.