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

时间:2015-10-08 18:33:10

标签: php mysql database forms

更新: 我正在组建一个网站。其中一个页面要求我使用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>

这是UPDATED操作文件(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>';
}
?>

这里也是您的评论的insertemployee文件:

<?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>';
}
?>

1 个答案:

答案 0 :(得分:0)

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