我知道这个错误意味着您正在尝试访问不存在的数组元素。 但是,我仍然遇到这个PHP代码的问题,表单正在提交,因为我可以看到..
以确保我也尝试了POST值,并且它们都已提交并可用..
整个错误代码:未定义的索引:在'''''''''''''''''''''''''''''' 和未定义的索引:'''''''''''''''''''''''''''''''''''''''''''''''''''''
PHP代码
<?php
if (isset($_POST['Submit_insert'])) //Inserting
{
$pid = $_SESSION['provider_ID'];
$branch=$_GET['branch'];//as a number
$branch_name=$_GET['branch_name']; // as a string
$prid=$_POST['PRID'];
$name=$_POST['NAME'];
$manu=$_POST['MANU'];
$size=$_POST['SIZE'];
$price=$_POST['PRICE'];
$cat=$_POST['CAT'];
$newname="$pid$branch$prid.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"],"./images_store/" . $newname);
echo "Stored in: " . "./images_store/" . $_FILES["file"]["name"];
}
?>
HTML标记?
<form id='register' action='./controlPage.php?branch=".$branch_no."&branch_name=".$branch." ' method='post' accept-charset='UTF-8'>
<center>
<table border='0'>
<legend>Inserting a Record in the " . $branch /*From the form*/ . " of " . $_SESSION['provider_name'] . "</legend>
<br>
<tr>
<td>Product ID :
<td height='39'><input type='text' name='PRID' />
<tr>
<td>Product Name :
<td height='39'><input type='text' name='NAME' />
<tr>
<td>Product Manufacturer :
<td height='39'><input type='text' name='MANU' />
<tr>
<td>Product Size/Weight :
<td height='39'><input type='text' name='SIZE' />
<tr>
<td>Product Price :
<td height='39'><input type='text' name='PRICE' />
<tr>
<td>Image File :
<td><input type='file' name='file' id='file'>
<tr>
<td>Product Category :
<td height='39'><select name='CAT'>
<option value='GOODS'>GOODS</option>
<option value='FROZEN GOODS'>FROZEN GOODS</option>
<option value='DAIRY'>DAIRY</option>
<option value='DELI MEAL'>DELI MEAL</option>
<option value='BAKERY/PASTRY'>BAKERY/PASTRY</option>
<option value='DRINKS'>DRINKS</option>
<option value='CANDIES/COOKIES'>CANDIES/COOKIES</option>
<option value='HEALTH/HYGINE'>HEALTH/HYGINE</option>
<option value='GIFTS'>GIFTS</option>
</select>
<tr>
<td >
<td height='34'></br>
<input type='submit' name='Submit_insert' value='Create a Record' />
</table>
</fieldset>
<table border='0'>
<tr>
</tr>
</table>
</center>
</form>
答案 0 :(得分:2)
您忘记了表单中的enctype:
<form id='register' enctype="multipart/form-data" action='./controlPage.php?branch=".$branch_no."&branch_name=".$branch." ' method='post' accept-charset='UTF-8'>