gpt4 book ai didi

php - 更新使用 mysql 提交特定于此代码的 PHP 表单

转载 作者:行者123 更新时间:2023-11-29 21:57:15 24 4
gpt4 key购买 nike

更新:我正在整理一个网站。其中一个页面要求我使用 mysql(通过 xampp、phpmyadmin)向服务器提交表单。不幸的是,我不断收到以下通知错误:

未定义索引:第 34 行 C:\xampp\htdocs\pet-shop\includes\CustomerForm.php 中的 PetType

当我尝试以任何方式提交表单时,它会给出以下消息:

未找到对象!

在此服务器上找不到所请求的 URL。引用页面上的链接似乎错误或已过时。请将该错误告知该页面的作者。

如果您认为这是服务器错误,请联系网站管理员。错误404本地主机Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15

这里有很多代码,所以请让我知道发布此代码的好地方。谢谢。

以下是实际网页 (GroomingServices.php) 的更新代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="PSStyles.css" rel="stylesheet" type="text/css" />
<title>Grooming</title>
</head>

<body>

<div id="wrapper">
<?php include 'header1.php';?>
</div>




<div id="ripmain">
<div id="menuet">

<nav>
<ul id="menubar">
<li><a href="index.php">Home</a></li>
<li><a href="AboutUs.php">About</a></li>
<li><a href="Location.php">Location</a></li>
<li><a href="GroomingServices.php">Grooming</a></li>
<li><a href="ContactUs.php">Contact Us</a></li>

</ul>
</nav>

</div>

<div id="main">
<div id="menu">
<h2>Specials</h2>

<p>Check out our specials for this month:</p>

<navside>
<ul id="menubar2">
<li>$20 of baths Dogs and Cats</li>
<li>Teeth brushing 50% off with bath</li>
<li>Paw-di-cure $10</li>
</ul>
</navside>
<br />
<h2>Regular Perks</h2>
<p>
Teeth care: $10<br />
Baths: <br /> <li>0-10 lbs = $5; </li>
<li>10-20 lbs = $10;</li>
<li>20-30 lbs = $15; </li>
<li>30-50 lbs = $20; </li>
<li>Over 50 lbs = $30 and up; </li>
De-shedding: ask<br />
Nail trimming: $5<br />
Massage: $5-$10<br />
</p>

</div>

<div id="content">
<h1>Make your pet reservations here.</h1>
<p>The Pet Perks we offer:</p>

<form method="post" action="InsertEmployee.php">

<div>
<table>
<tr>
<td>First name:</td>
<td><input type="text" name="FirstName" size="40" required></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="text" name="LastName" size="40" required></td>
</tr><tr>
<td>Address:</td>
<td><input type="text" name="Address" size="40" required></td>
</tr><tr>
<td>City:</td>
<td><input type="text" name="City" size="40" required></td>
</tr><tr>
<td>State:</td>
<td><input type="text" name="State" size="40" required></td>
</tr>
<tr>
<td>Zip:</td>
<td><input type="text" name="Zip" size="40" required></td>
</tr>
<tr>
<td>Phone Number:</td>
<td><input type="text" name="PhoneNumber" size="40" required></td>
</tr>
<tr>
<td height="44">Email:</td>
<td><input type="text" name="Email" value="" size="25" maxlength="40"></td>
</tr>


<tr>
<td>
<label for="typeofPet">Type of Pet:</label>
<select name="typeofPet" id="typeofPet" required>
<option value="0" selected="selected"></option>
<optgroup label="Cat">
<option value="Cat">Cat</option>
<optgroup label="Dog">
<option value="Lab">Lab</option>
<option value="Chow">Chow</option>
<option value="Terrier">Terrier</option>
<option value="Bulldog">Bulldog</option>
<option value="Cocker Spaniel">Cocker Spaniel</option>
<option value="Great Dane">Great Dane</option>
<option value="Alaskan Huskey">Alaskan Huskey</option>
</optgroup>
</optgroup>
</select>
</td>
</tr>

<tr>
<td>Pet Name:</td>
<td><input type="text" name="PetName" value="" size="25" maxlength="40" required></td>
</tr>

<tr>
<td>Neutered or Spayed:</td>
<td>
<input type="checkbox" name="neutered" id="neutered"> <label for="neutered">Neutered</label>
<input type="checkbox" name="spayed" id="spayed"> <label for="spayed">Spayed</label>
</td>
</tr>

<tr>
<td>Pet Age:</td>
<td><input type="text" name="PetAge" id="petage" value="" size="25" maxlength="40"></td>
</tr>

<tr>
<td colspan="2" height="20">
<input type="hidden" name="discount" id="discount" value="20%">

<input type="submit" value="Submit">
<input type="reset" value="Reset">
</td>
</tr>

</table>
</div>
</form>

<div class="clearer"></div>
</div>

<?php include 'footer1.php';?>
</div>
</div>
</div>
</body>
</html>

这是更新后的操作文件 (InsertEmployee.php):

<?php
$dbEntries = $_POST;
foreach ($dbEntries as &$entry)
{
$entry = dbString($entry);
}

@$db = new mysqli('localhost','root','pyth0n1','pet_shop');
if (mysqli_connect_errno())
{
echo 'Cannot connect to database: ' . mysqli_connect_error();
}
$query = "INSERT INTO grooming
(FirstName, LastName, Title, Address, City, State, Zip, PhoneNumber, Email, PetType, Breed, PetName, NeuteredOrSpayed, PetAge)
VALUES ('" . $dbEntries['FirstName'] . "','" .
$dbEntries['LastName'] . "','" .
$dbEntries['Address'] . "','" .
$dbEntries['City'] . "','" .
$dbEntries['State'] . "','" .
$dbEntries['Zip'] . "','" .
$dbEntries['PhoneNumber'] . "','" .
$dbEntries['Email'] . "','" .
$dbEntries['PetType'] . "-" .
$dbEntries['Breed'] . "-" .
$dbEntries['PetName'] . "','" .
$dbEntries['NeuteredOrSpayed'] . "-" .
$dbEntries['Spayed'] . "-" .
$dbEntries['Neutered'] . "-" .
$dbEntries['PetAge'] . "')";

if ($db->query($query))
{
echo '<div align="center">Customer Added</div>
<a href="CustomerReport.php">Customer Report</a>';
$showForm = false;
}
else
{
echo '<div align="center">Insert failed</div>';
}
?>

这也是供您查看的 inserttemployee 文件:

<?php
$dbEntries = $_POST;
foreach ($dbEntries as &$entry)
{
$entry = dbString($entry);
}

@$db = new mysqli('localhost','root','pyth0n1','pet_shop');
if (mysqli_connect_errno())
{
echo 'Cannot connect to database: ' . mysqli_connect_error();
}
$query = "INSERT INTO grooming
(FirstName, LastName, Address, City, State, Zip, PhoneNumber, Email, PetType, PetName, NeuteredOrSpayed, PetAge)
VALUES ('" . $dbEntries['FirstName'] . "','" .
$dbEntries['LastName'] . "','" .
$dbEntries['Address'] . "','" .
$dbEntries['City'] . "','" .
$dbEntries['State'] . "','" .
$dbEntries['Zip'] . "','" .
$dbEntries['PhoneNumber'] . "','" .
$dbEntries['Email'] . "','" .
$dbEntries['PetType'] . "-" .
$dbEntries['PetName'] . "','" .
$dbEntries['NeuteredOrSpayed'] . "-" .
$dbEntries['Spayed'] . "-" .
$dbEntries['Neutered'] . "-" .
$dbEntries['PetAge'] . "')";

if ($db->query($query))
{
echo '<div align="center">Customer Added</div>
<a href="CustomerReport.php">Customer Report</a>';
$showForm = false;
}
else
{
echo '<div align="center">Insert failed</div>';
}
?>

最佳答案

您错过了 value 中 Title 字段的传递值。

关于php - 更新使用 mysql 提交特定于此代码的 PHP 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33023420/

24 4 0
文章推荐: html - 当