我需要将表单提交到数据库,我的表单及其用于提交到数据库的 php 代码在本地服务器中正常工作,但是当我在提交后将其上传到主服务器时,会显示一个空的 php 文件,没有错误消息,数据也没有输入数据库,当我包含上传图像的 php 代码时,会出现此问题,否则表单中的其他详细信息会成功提交.....
作为一个学习者,所有类型的建议都是可观的....在此先感谢
<?php
error_reporting(E_ALL);
$name = $_POST['name'];
$date = $_POST['year']."-". $_POST['month']."-".$_POST['date'];
$date = mysql_real_escape_string($date);
if (isset($_POST['gender'])){
$gender = $_POST['gender'];
}
if (isset($_POST['maritalstatus'])){
$maritalstatus = $_POST['maritalstatus'];
}
$registerby =$_POST['registerby'];
$livingplace =$_POST['livingplace'];
$qualification =$_POST['quali'];
$occupation =$_POST['occupation'];
$income = $_POST['income'];
$contactno =$_POST['mobno'];
$caste =$_POST['caste'];
$email =$_POST['email'];
if(isset($_POST['submit']))
{
//Assign the paths needed to variables for use in the script
$filePathFull = "/public_html/www.****.com/icons/".$_FILES["imagefile"] ["name"];
$filePathThumb = "/public_html/www.*****.com/icons/";
//Assign the files TMP name and TYPE to variable for use in the script
$tmpName = $_FILES["imagefile"]["tmp_name"];
$imageType = $_FILES["imagefile"]["type"];
//Use a switch statement to check the extension of the file type. If file type is not valid echo an error
switch ($imageType) {
case $imageType == "image/gif":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/jpeg":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/pjpeg":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/png":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/x-png":
move_uploaded_file($tmpName,$filePathFull);
break;
default:
echo 'Wrong image type selected. Only JPG, PNG or GIF formats accepted!.';
}
// Get information about the image
list($srcWidth, $srcHeight, $type, $attr) = getimagesize($filePathFull);
$origRatio = $srcWidth/$srcHeight;
//Create the correct file type based on imagetype
switch($type) {
case IMAGETYPE_JPEG:
$startImage = imagecreatefromjpeg($filePathFull);
break;
case IMAGETYPE_PNG:
$startImage = imagecreatefrompng($filePathFull);
break;
case IMAGETYPE_GIF:
$startImage = imagecreatefromgif($filePathFull);
break;
default:
return false;
}
//Get the image to create thumbnail from
$startImage;
$width = 150;
$height = 150;
if ($width/$height > $origRatio) {
$width = $height*$origRatio;
}else{
$height = $width/$origRatio;
}
//Create the thumbnail with true colours
$thumbImage = imagecreatetruecolor($width, $height);
//Generate the resized image image
imagecopyresampled($thumbImage, $startImage, 0,0,0,0, $width, $height, $srcWidth, $srcHeight);
//Generate a random number to append the filename.
$ran = "thumb_".rand () ;
$thumb2 = $ran.".jpg";
//global $thumb_Add_thumb;
//Create the path to store the thumbnail in.
$thumb_Add_thumb = $filePathThumb;
$thumb_Add_thumb .= $thumb2;
//Create the new image and put it into the thumbnails folder.
imagejpeg($thumbImage, "" .$filePathThumb. "$thumb2");
}
if(isset($_POST['submit']))
{
$connection = mysql_connect("localhost","user", "pass");
if(! $connection) { die('Connection Failed: ' . mysql_error()) ;}
mysql_select_db("database") or die (error.mysql_error());
$sql = "INSERT INTO quickregister(Name,Gender,Dateofbirth,Maritalstatus,Qualification,Income,Livingplace,Caste,Contactno,Emailaddress,Registerby,picture,filePathThumb,Occupation)VALUES('".$name."','".$gender."','".$date."','".$maritalstatus."','".$qualification."','".$income."','".$livingplace."','".$caste."','".$contactno."','".$email."','".$registerby."','".$filePathFull."','".$thumb_Add_thumb."','".$occupation."')";
$retval = mysql_query( $sql, $connection );
if(! $retval )
{
die('Could not enter data' . mysql_error());
}
echo "<b>Your data was added to database</b>";
}
?>