作者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/m.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