dongpang2483 2015-10-08 18:33
浏览 34

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

UPDATED: I'm putting together a website. One of the pages calls for me to submit a form to the server using mysql (through xampp, phpmyadmin). Unfortunately, I keep getting the following notice error:

Undefined index: PetType in C:\xampp\htdocs\pet-shop\includes\CustomerForm.php on line 34

when I try to submit the form any way, it tells gives the following message:

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15

there's a lot of code here so please let me know what would be a good place to post this. Thanks.

Here's the UPDATED code for the actual webpage (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>

And here's the UPDATED action file (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>';
}
?>

here's the insertemployee file for your review as well:

<?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条回答 默认 最新

  • doulu6314 2015-10-12 04:59
    关注

    You miss the passing value of Title field in value.

    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行