[请益] 变量未定义问题?

楼主: joinbee (farewell 我的童年)   2021-11-09 14:11:19
<?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身上,请指教一下
作者: cf1064 (蚵仔)   2021-11-09 14:37:00
在$_POST["guestName"]的时候就要先判断这个有没有东西
作者: shadowjohn (转角遇到爱)   2021-11-09 16:47:00
error_reporting(E_ALL & ~E_NOTICE); 嗯...
作者: Jerr (身为老爸老妈噜..)   2021-11-10 11:55:00
没有不能动啊只是 waring 而已 (拉椅子)
作者: MoMoShota (正太控)   2021-11-10 14:38:00
把变量直接丢 SQL Query...(吃瓜
作者: MOONRAKER (㊣牛鹤鳗毛人)   2021-11-11 13:50:00
拿阵列里面没有的元素还不会错 好像是php4的事情了变量跟阵列里面的项目是两回事情

Links booklink

Contact Us: admin [ a t ] ucptt.com