Php 未定义索引:pImage行92,93,94 $street\u address=NULL; $price=NULL; $number_卧室=空; $number_baths=NULL; $sq_ft=零; $year\u builded=NULL; $featured=NULL; $pImage=NULL; //为特色房屋项目的复选框值创建存储空间。 $pool=0; $finished_地下室=0; $fenced_码=0; if(isset($\u POST['submit']){//检查用户是否提交表单。 //print_r($_POST);//这将显示要在屏幕上发布的数组信息 //print_r($_FILES);//可用于查看数组的内容 //从帖子中收集主页列表数据 如果(isset($_POST['pImage'])){ $pImage=$_POST['pImage']; } $street\u address=$\u POST['street\u address']; $price=$_POST['price']; $number_bedrooms=$_POST['number_bedrooms']; $number\u baths=$\u POST['number\u baths']; $sq_ft=$sq_POST['sq_ft']; $year\u builded=$\u POST['year\u builded']; $pDesc=$_POST['pDesc']; if(isset($\u POST['featured']){//用于检查用户是否选择了该主页,如果该主页被选择为featured。如果他们没有选择,则该项目不会传递给该帖子。 $featured=$_POST['featured']; }否则{ $featured=NULL; } 如果(isset($_POST['pool'])){ $pool=$_POST['pool']; }否则{ $pool=0; }//此结束括号已“附加”到进程检查,以查看复选框是否已“勾选”。 //工艺检查已完成的地下室箱。 如果(isset($_POST['finished_subground'])){ $finished_subground=$_POST['finished_subground']; }否则{ $finished_地下室=0; }//结束已完成的检查复选框检查 //过程检查了围栏围场箱。 如果(设置($_POST['fenced_yard']){//fenced yard复选框过程检查 $fenced_yard=$_POST['fenced_yard']; }否则{ $fenced_码=0; }//结束已完成的检查复选框检查 }//结束$#提交后检查(从第40行开始) //街道地址验证检查-查看是否在表单中输入了地址。 如果(空($street_address)){ echo“您没有填写街道地址。”; $output\u form=true;//将打印表单。 }//街道尽头\地址检查 //图像、价格和图像验证检查 //价格验证检查-查看价格是否作为数字输入表单。 如果(!is_numeric($price)){//不是数字函数。 echo“你们并没有把价格填成数字。”; $output\u form=true;//将打印表单。 } //用于存储用于上载图像的信息关联数组。 $pImage=$_文件['pImage']['name']//数组变量。从02fileglobaladd.txt文档中提取的代码$_用于存储uploa文件信息的文件 $pImage_type=$_文件['pImage']['type']; $pImage_size=$_文件['pImage']['size']; //图像文件大小验证检查--检查以确保上载的图像不大于1 MB 如果(!empty($pImage)){//empty表示文件名。 如果(($pImage_type=='image/gif')| |($pImage_type=='image/jpeg')| |($pImage_type=='image/pjpeg')|($pImage_type=='image/png')) &&($pImage_size>0)和($pImage_size)
我在GET和POST语句中都添加了if-isset命令,有人能帮我吗?我知道在解决了这个问题后,我必须对代码进行很多修改。我的教授提到使用print-r语句Php 未定义索引:pImage行92,93,94 $street\u address=NULL; $price=NULL; $number_卧室=空; $number_baths=NULL; $sq_ft=零; $year\u builded=NULL; $featured=NULL; $pImage=NULL; //为特色房屋项目的复选框值创建存储空间。 $pool=0; $finished_地下室=0; $fenced_码=0; if(isset($\u POST['submit']){//检查用户是否提交表单。 //print_r($_POST);//这将显示要在屏幕上发布的数组信息 //print_r($_FILES);//可用于查看数组的内容 //从帖子中收集主页列表数据 如果(isset($_POST['pImage'])){ $pImage=$_POST['pImage']; } $street\u address=$\u POST['street\u address']; $price=$_POST['price']; $number_bedrooms=$_POST['number_bedrooms']; $number\u baths=$\u POST['number\u baths']; $sq_ft=$sq_POST['sq_ft']; $year\u builded=$\u POST['year\u builded']; $pDesc=$_POST['pDesc']; if(isset($\u POST['featured']){//用于检查用户是否选择了该主页,如果该主页被选择为featured。如果他们没有选择,则该项目不会传递给该帖子。 $featured=$_POST['featured']; }否则{ $featured=NULL; } 如果(isset($_POST['pool'])){ $pool=$_POST['pool']; }否则{ $pool=0; }//此结束括号已“附加”到进程检查,以查看复选框是否已“勾选”。 //工艺检查已完成的地下室箱。 如果(isset($_POST['finished_subground'])){ $finished_subground=$_POST['finished_subground']; }否则{ $finished_地下室=0; }//结束已完成的检查复选框检查 //过程检查了围栏围场箱。 如果(设置($_POST['fenced_yard']){//fenced yard复选框过程检查 $fenced_yard=$_POST['fenced_yard']; }否则{ $fenced_码=0; }//结束已完成的检查复选框检查 }//结束$#提交后检查(从第40行开始) //街道地址验证检查-查看是否在表单中输入了地址。 如果(空($street_address)){ echo“您没有填写街道地址。”; $output\u form=true;//将打印表单。 }//街道尽头\地址检查 //图像、价格和图像验证检查 //价格验证检查-查看价格是否作为数字输入表单。 如果(!is_numeric($price)){//不是数字函数。 echo“你们并没有把价格填成数字。”; $output\u form=true;//将打印表单。 } //用于存储用于上载图像的信息关联数组。 $pImage=$_文件['pImage']['name']//数组变量。从02fileglobaladd.txt文档中提取的代码$_用于存储uploa文件信息的文件 $pImage_type=$_文件['pImage']['type']; $pImage_size=$_文件['pImage']['size']; //图像文件大小验证检查--检查以确保上载的图像不大于1 MB 如果(!empty($pImage)){//empty表示文件名。 如果(($pImage_type=='image/gif')| |($pImage_type=='image/jpeg')| |($pImage_type=='image/pjpeg')|($pImage_type=='image/png')) &&($pImage_size>0)和($pImage_size),php,Php,我在GET和POST语句中都添加了if-isset命令,有人能帮我吗?我知道在解决了这个问题后,我必须对代码进行很多修改。我的教授提到使用print-r语句 感谢您的帮助……我是PHP的新手,问题在于这句话: $street_address = NULL; $price = NULL; $number_bedrooms = NULL; $number_baths = NULL; $sq_ft = NULL; $year_built = NULL; $featured
感谢您的帮助……我是PHP的新手,问题在于这句话:
$street_address = NULL;
$price = NULL;
$number_bedrooms = NULL;
$number_baths = NULL;
$sq_ft = NULL;
$year_built = NULL;
$featured = NULL;
$pImage = NULL;
//create storage for the checkbox values for featured house items.
$pool = 0;
$finished_basement = 0;
$fenced_yard = 0;
if (isset($_POST['submit'])) {//checks to see if the user submit the form.
// print_r ($_POST); // This will show you what array information is being sent to post on the screen
//print_r ($_FILES); //can be used to view the contents of an array
// Gather the home listing data from the POST
if(isset($_POST['pImage'])) {
$pImage = $_POST['pImage'];
}
$street_address = $_POST['street_address'];
$price = $_POST['price'];
$number_bedrooms = $_POST['number_bedrooms'];
$number_baths = $_POST['number_baths'];
$sq_ft = $_POST['sq_ft'];
$year_built = $_POST['year_built'];
$pDesc = $_POST['pDesc'];
if (isset($_POST['featured']) ) { //used to check whether the user selected if the home was selected as featured. If they didn't the item is not passed to the POST.
$featured = $_POST['featured'];
} else {
$featured = NULL;
}
if (isset($_POST['pool']) ) {
$pool = $_POST['pool'];
} else {
$pool = 0;
} // this end bracket is "attached" to the process checking to see if the checkbox was 'ticked'.
//process checked finished basement box.
if (isset($_POST['finished_basement']) ) {
$finished_basement = $_POST['finished_basement'];
} else {
$finished_basement = 0;
} // end of finished_basement checkbox check
//process checked fenced yard box.
if (isset($_POST['fenced_yard']) ) { // Fenced Yard Checkbox Process Check
$fenced_yard = $_POST['fenced_yard'];
} else {
$fenced_yard = 0;
} // end of finished_basement checkbox check
} // end of $_POST submission check (starts on line #40)
// Street Address Validation Check - See if address was entered into the form.
if (empty($street_address)) {
echo "You didn't fill in a streetaddress. <br />";
$output_form = true; // will print form.
} // end of street_address check
// Image , Price & Image validation check
// Price Validation Check - See if Price was entered into the form as a number.
if (!is_numeric($price)) { //is not a number function.
echo "You didn't fill in price as a number.";
$output_form = true; // will print form.
}
// Used to store information for uploading images associative array.
$pImage = $_FILES['pImage']['name']; //array variable. Code pulled from 02fileglobaladd.txt document. $_FILES used to store file information from uploa
$pImage_type = $_FILES['pImage']['type'];
$pImage_size = $_FILES['pImage']['size'];
// Image File Size Validation check -- checks to be sure that the uploaded image is no larger than 1 MB
if (!empty($pImage)) { // empty is for name of file.
if ((($pImage_type == 'image/gif') || ($pImage_type == 'image/jpeg') || ($pImage_type == 'image/pjpeg') || ($pImage_type == 'image/png'))
&& ($pImage_size > 0) && ($pImage_size <= GW_MAXFILESIZE)) { // check to make sure that the file type is valid and that the file is larger than 0 but less than 1meg
if ($_FILES['pImage']['error'] == 0) { // test to be sure file gets uploaded.
$target = GW_UPLOADPATH . $pImage; // try to move file to images folder // FILE UNIQUE time function added from book (page 252) that duplicates and chages file name if there
// is more than one version
if (move_uploaded_file($_FILES['pImage']['tmp_name'], $target)) {
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Write the data to the database
$query = "INSERT INTO homes ( street_address, price, number_bedrooms, number_baths, sq_ft, year_built, pool, finished_basement, fenced_yard, featured, pDesc, pImage ) " .
"VALUES ('$street_address', '$price', '$number_bedrooms', '$number_baths', '$sq_ft', '$year_built', '$pool', '$finished_basement', '$fenced_yard', '$featured', '$pDesc','$pImage')";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
/* Testing echos
echo $query;
echo '<br />'
/**/
// Confirmation for the user that will be displayed once the user clicks the submit button (As long as there are no errors with the PHP code)
echo '<p>Thank you for Your Submission. The home has been added to the database.</p>';
echo 'Street Address: ' . $street_address . '<br />';
echo 'Price: ' . $price . '<br />';
echo 'Number of Bedrooms: ' . $number_bedrooms . '<br />';
echo 'Number of Baths: ' . $number_baths . '<br />';
echo 'Square Feet: ' . $sq_ft . '<br />';
echo 'Year Built: ' . $year_built . '<br />';
// featured if statement
echo 'Featured:' ;
if ($featured = 1) {echo ' Yes <br />'; } else {echo ' No <br /> ';}
//example of using ternary format of if/else -- additional items of home (pool, finished basement, fenced in yard ) checkboxes
echo 'Pool: ' . (($pool) ? 'YES' : 'NO' ). '<br />' ;
echo 'Finished Basement: ' . (($finished_basement) ? 'YES' : 'NO' ). '<br />' ;
echo 'Fenced Yard: ' . (($fenced_yard) ? 'YES' : 'NO' ). '<br />' ;
echo 'Desc:<span class="desc"> ' . ($pDesc). '</span><br />';
echo 'Image File: ';
echo '<img src= " ' . GW_UPLOADPATH . $pImage . ' " alt="Homes Image" /></p>';
echo '<p><a href="index.php"><< Back to Listings Page.</a></p>';
// Clear the data in the form
$street_address = "";
$price = "";
$number_bedrooms = "";
$number_baths = "";
$sq_ft = "";
$year_built = "";
$pool = "";
$finished_basement = "";
$featured = "";
$pImage = "";
$pDesc ="";
mysqli_close($dbc);
} //movefile worked....
else { //movefile didn't work... error message is printed out
echo '<p class="error">Sorry, there was a problem loading your product image.</p>';
}
}
} // no file type or size error / ENDING BRACKET
else { // there was a file type or size error / ENDING BRACKET
echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>';
} // type size error message printed. / ENDING BRACKET
@unlink($_FILES['pImage']['tmp_name']); // unlink is php command to delete the file. Its getting rid of the temporary file. @ symbol ignores any error message.
} // data validated
else { // data didn't validate, show error message.
echo '<p class="error">Please enter all the required product information.</p>';
}
?>
由于$\u POST['pImage']
是图像,因此不能使用$\u POST
。要检查它是否已上载,只需使用:
if(isset($_POST['pImage'])) {
$pImage = $_POST['pImage'];
}
这将检查图像的名称,如果可用,将返回true
这种说法是错误的:
if($_FILES['pImage']['name') {
有关PHP运算符的详细信息:
此外,您不应禁止显示错误消息:
if ($featured == 1) {echo ' Yes <br />'; } else {echo ' No <br /> ';}
删除@以启用错误报告。它在诊断语法错误时非常有用。尝试回显
$\u POST['pImage']
:echo$\u POST['pImage'];
我将把它放在代码中的什么位置?如果(isset($\u POST['pImage']){$pImage=$\u POST['pImage']),你可以把它放在前面。这是为了检查该值是否已设置。我是否应该取出$pImage=$\u POST['pImage'];也可以重复?更改了它。在移动代码后,它工作了。谢谢!
if ($featured == 1) {echo ' Yes <br />'; } else {echo ' No <br /> ';}
@unlink($_FILES['pImage']['tmp_name']);