求一个php查询mysql,并返回结果的例子,详细点,谢谢啦,能答一定采纳,
给你发个简单的留言板
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script>
function clearform(){
document.getElementById("name").value="";
document.getElementById("email").value="";
document.getElementById("phone").value="";
document.getElementById("message").value="";
}
</script>
</h
<p>
<?php
$database_name = 'head_first_php';
$databese_link = 'localhost';
$databese_user = 'root';
$datebese_password = '';
define('GW_UPLOADPATH', 'images/');
function now()
{
return date('Y-m-d H:i:s',time());
}
$link = mysqli_connect($databese_link, $databese_user, $datebese_password,$database_name ) or die("连接失败1");
mysqli_query($link,"SET NAMES 'utf8'");
mysqli_query($link,"SET CHARACTER_SET_CLIENT=utf8");
mysqli_query($link,"SET CHARACTER_SET_RESULTS=utf8");
if(isset($_POST['submit']))
{
$name = mysqli_real_escape_string($link, trim($_POST['name']));
$email = mysqli_real_escape_string($link, trim($_POST['email']));
$phone = mysqli_real_escape_string($link, trim($_POST['phone']));
$message = mysqli_real_escape_string($link, trim($_POST['message']));
$query = "INSERT INTO messageBoard ".
"(name,email,phone,message,data)".
"VALUES('$name','$email','$phone','$message',now())";
$result = mysqli_query($link, $query) or die("查询失败");
}
$query = "SELECT * FROM messageBoard ";
$result = mysqli_query($link, $query);
if($result)
{
while ($row = mysqli_fetch_array($result)) {
echo '发布时间 '.$row['data'].'<br />';
echo '姓名 '.$row['name'].'<br />';
echo '邮件 '.$row['email'].'<br />';
echo '电话 '.$row['phone'].'<br />';
echo '<textarea cols="40" rows="20" readonly="false">'.$row['message'].'</textarea>';
echo '<br />-------------------------------------------------------<br />';
}
}else {
}
mysqli_close($link);
?>
</p>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" >
<label for="name">你的昵称</label>
<input type="text" name="name" id="name" value=" ">
<br />
<label for="name">你的邮件</label>
<input type="text" name="email" id="email" value=" ">
<br />
<label for="name">上联系电话</label>
<input type="text" name="phone" id="phone">
<br />
你的留言<br />
<textarea name="message" id="message" cols="40" rows="20"></textarea>
<br />
<input type="submit" name="submit" value="点击提交"> <input type="button" onclick="clearform()" value="清空">
</form>
<br />
<a href="../index.php">点击返回主页</a>
</body>
</html>
数据库结构
mysql_select_db('test',$link);
mysql_query('set names utf8');
$sql = "select * from test";
$result = mysql_query($sql);
while($ROW = mysql_fetch_assoc($result)){
echo $ROW['id'];
echo $ROW['name'];
echo $ROW['pwd'];
}
这里的id,name,pwd是test数据库中的test表中的字段名
我想要的是整个php页面。呵呵,谢谢咯,你有以前的作品吗?