作者joinbee (farewell 我的童年)
看板PHP
标题[请益] 变数未定义问题?
时间Tue Nov 9 14:11:19 2021
<?php
require("connect.php");
$guestName=$_POST["guestName"];
$guestEmail=$_POST["guestEmail"];
$guestGender=$_POST["guestGender"];
$guestSubject=$_POST["guestSubject"];
$guestContent=$_POST["guestContent"];
$guestTime = date("Y:m:d H:i:s",time()+28800);
if(isset($guestName)){
mysqli_query($link,"insert into guest
value('','$guestName','$guestEmail','$guestGender','$guestSubject','$guestTime','$guestContent','','')");
header("location:p13-show.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我要留言</title>
<link rel="stylesheet"
href="
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>
<style>
.container{
margin:auto;
background-color:#f5f5f5;
width:800px;
padding-bottom: 20px;
}
.button{
text-align:center;
padding:20px 0;
}
.top h3{
font-family:微软正黑体;
text-align:center;
padding:10px 0;
}
.form-group{
font-family:微软正黑体;
font-size:16px;
}
</style>
<body>
<div class="container">
<div class="top">
<h3>新增留言</h3>
</div>
<form id="form1" name="form1" method="post" action=""
class="form-horizontal">
<div class="form-group">
<label for="guestName" class="col-sm-4 control-label">昵称:
</label>
<div class="col-sm-6">
<input type="text" class="form-control" placeholder="您的昵称
" name="guestName" id="guestName" />
</div>
</div>
<div class="form-group">
<label for="guestEmail" class="col-sm-4 control-label">信箱:
</label>
<div class="col-sm-6">
<input type="text" class="form-control" placeholder="您的信箱
" name="guestEmail" id="guestEmail" />
</div>
</div>
<div class="form-group">
<label for="guestGender" class="col-sm-4 control-label">性别:
</label>
<label class="radio-inline">
<input type="radio" name="guestGender" id="radio" value="男"
/> 男
</label>
<label class="radio-inline">
<input type="radio" name="guestGender" id="radio2" value="女"
/>女
</label>
</div>
<div class="form-group">
<label for="guestSubject" class="col-sm-4 control-label">留言主旨
:</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="guestSubject"
id="guestSubject" />
</div>
</div>
<div class="form-group">
<label for="guestContent" class="col-sm-4 control-label">留言内容:
</label>
<div class="col-sm-6">
<textarea name="guestContent" class="form-control"
id="guestContent" rows="5"></textarea>
</div>
</div>
<div class="button">
<input type="submit" name="button" id="button" value="送出"
class="btn"/>
</div>
</form>
</div>
</body>
</html>
请问各位高手,不好意思我不懂怎麽贴到网路上,所以只好贴在板上,排版很丑请见谅
我在写一个留言板,但连上留言版都会显示Warning: Undefined array key "guestName" in C:\xampp\htdocs\hello.php on line
4
Warning: Undefined array key "guestEmail" in C:\xampp\htdocs\hello.php on
line 5
Warning: Undefined array key "guestGender" in C:\xampp\htdocs\hello.php on
line 6
Warning: Undefined array key "guestSubject" in C:\xampp\htdocs\hello.php on
line 7
Warning: Undefined array key "guestContent" in C:\xampp\htdocs\hello.php on
line 8
请问一下,php的变数不是不用宣告吗?还是问题是出在Html身上,请指教一下
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.164.209.141 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PHP/M.1636438285.A.74E.html
1F:推 cf1064: 在$_POST["guestName"]的时候就要先判断这个有没有东西 11/09 14:37
2F:→ shadowjohn: error_reporting(E_ALL & ~E_NOTICE); 嗯... 11/09 16:47
3F:→ Jerr: 没有不能动啊只是 waring 而已 (拉椅子) 11/10 11:55
4F:→ MoMoShota: 把变数直接丢 SQL Query...(吃瓜 11/10 14:38
5F:→ MOONRAKER: 拿阵列里面没有的元素还不会错 好像是php4的事情了 11/11 13:50
6F:→ MOONRAKER: 变数跟阵列里面的项目是两回事情 11/11 13:51
※ 编辑: joinbee (220.143.36.87 台湾), 11/13/2021 21:34:24