gpt4 book ai didi

php - 简单的 php "Undefined index"表单提交错误

转载 作者:行者123 更新时间:2023-12-01 00:10:18 24 4
gpt4 key购买 nike

除了 $fname$mname$lname 之外,我对每个 $_POST 项目都收到此错误.我不明白为什么。我已经搜索了一个解决方案,isset 的建议是最常见的,但我已经尝试了几种不同的形式,但它仍然不适合我。

注意:未定义索引:第13行C:\xampp\htdocs\php\signin.php中的 zip

注意:第15行C:\xampp\htdocs\php\signin.php中未定义索引:homephone

注意:第16行C:\xampp\htdocs\php\signin.php中未定义索引:mobphone

signin.php

<?php

if(isset($_POST['submit'])) {

$fname=$_POST['firstname'];
$mname=$_POST['middlename'];
$lname=$_POST['lastname'];
$dob=$_POST['dateofbirth'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$postcode=$_POST['postcode'];
$email=$_POST['email'];
$homephone=$_POST['homephone'];
$mobphone=$_POST['mobphone'];
$preferred=$_POST['preferred'];

include_once("includes/link.php");

$sql=("INSERT INTO `member` VALUES ('$fname', '$mname', '$lname', '$dob', '$address', '$city', '$state', '$country', '$postcode', '$email', '$homephone', '$mobphone', 'preferred')");

mysqli_query($link, $sql);

mysqli_close($link);
}
?>

link.php

<?php

$hostname = "localhost";
$user = "root";
$password = "********";
$link = mysqli_connect($hostname, $user , $password);

if (!$link){
echo "server is being lame";
exit;
};
mysqli_select_db($link, "cp2cwonrlvDB3");
if (!mysqli_select_db($link, "cp2cwonrlvDB3")){
echo "Could not connect brudda";
};

?>

表单 html:

<html>
<head>
<title>Example form</title>
<style type="text/css">

label
{
width: 100px;
float: left;
text-align: right;
margin-right: 0.5em;
display: block
}

.reset {
margin-left:50px;
}

h3 {
margin-left:15px;
}

</style>
<script>
<?php
include 'includes/connection.php'
?>
</script>
</head>

<body>

<div class="container">
<h2>Sign up to CWON</h2>
<form method="POST" action="signin.php" novalidate>

<label for="fisrtname">First Name:</label>
<input type="text" name="firstname" required placeholder="Enter your first name" maxlength="25"><br />

<label for="middlename">Middle Name:</label>
<input type="text" name="middlename" placeholder="Enter your middle name" maxlength="25"><br />

<label for="lastname">Last Name:</label>
<input type="text" name="lastname" required placeholder="Enter your last name" maxlength="25"><br />

<label for="dateofbirth">Date of Birth:</label>
<input type="date" name="dateofbirth" required maxlength="25"><br />

<label for="address">Address:</label>
<input type="text" name="address" required maxlength="100" placeholder="Enter your home address"><br />

<label for="city">City:</label>
<input type="text" name="city" required maxlength="100" placeholder="Enter your city"><br />

<label for="state">State:</label>
<select name="state">
<option value="NSW">NSW</option>
<option value="QLD">QLD</option>
<option value="VIC">VIC</option>
<option value="SA">SA</option>
<option value="WA">WA</option>
<option value="NT">NT</option>
<option value="TAS">TAS</option>
</select> <br />

<label for="country">Country:</label>
<input type="text" name="country" required maxlength="100" placeholder="Enter your country"><br />

<h3>Preferred contact:</h3>
<label for="preferred">Home Phone:</label>
<input type="radio" name="preferred" value="Home Phone"><br /><br />

<label for="preferred">Mobile Phone:</label>
<input type="radio" name="preferred" value="Mobile Phone"><br /><br />

<label for="preferred">Email:</label>
<input type="radio" name="preferred" value="Email"><br /><br />

<label for="homenumber">Home Number:</label>
<input type="text" name="homenumber" placeholder="Enter your home number"><br />

<label for="mobnumber">Mobile Number:</label>
<input type="text" name="mobnumber" placeholder="Enter your mobile number"><br />

<label for="email">Email Address:</label>
<input type="email" name="email" required maxlength="100" placeholder="Enter your email address"><br />

<label for="postcode">Postcode:</label>
<input type="number" name="postcode" required min="1000" max="9999" placeholder="4-digit"><br />

<label for="occupation">Occupation:</label>
<input type="text" name="occupation" maxlength="50" placeholder="Enter your occupation"><br />

<label for="hobbies">Hobbies:</label>
<input type="text" name="hobbies" maxlength="200" placeholder="separate with commas"><br />

<label for="interest">Interests:</label>
<select name="interest">
<option value="Fund Raisers">Fund Raisers</option>
<option value="Domestic Volunteering">Domestic Volunteering</option>
<option value="Foreign Volunteering">Foreign Volunteering</option>
<option value="All of the above">All of the above</option>
</select> <br /><br />

<label for="terms">Terms and Conditions</label>
<input type="checkbox" name="terms"><br /><br /><br />

<label for="newsletter">Sign up for the CWON newsletter</label>
<input type="checkbox" name="newsletter"><br /><br /><br /><br />

<input type="reset" name="reset" value="Reset" class="reset" onclick="set_focus()" />
<input type="submit" name="submit" value="Submit" class="submit">

</form>
</div>

最佳答案

看到 $_POST 数组中有 $。全部删除。

 $dob=$_POST['$dateofbirth'];
^------------------ That (Remove them all)

编辑:

您需要更改邮政编码的名称,因为它反射(reflect)了移动电话。

 <label for="postcode">Postcode:</label>
<input type="number" name="postcode" required min="1000" max="9999" placeholder="4-digit"><br />

现在将它们更改为...

$homephone=$_POST['homenumber']; //<--- Should be homenumber.`
$mobphone =$_POST['mobnumber'];
$postcode =$_POST['postcode'];

关于php - 简单的 php "Undefined index"表单提交错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23421834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com