MySQL所有变量都没有传递数据

时间:2014-12-06 14:59:33

标签: php mysql

我遇到了向mysql发送变量数据的问题,我的一个变量正在传递,但其他变量没有。

<?php 
session_start();
if(!isset($_SESSION["PAT_ID"])){
ob_start();
header("location: login.php");
ob_end_flush(); 
}

$patient_id ="";
$complainID = "";

$patient_id = $_SESSION["PAT_ID"];

if(isset($_GET["ComplainID"])){

$complainID = $_GET["ComplainID"];
}

include "config/connect_to_mysql.php";
?>

<?php 
//Diesease photo\

echo "Hello Patient Your Complain ID: " . $complainID;

$imageerr = "";
$typeerr = "";
$sizeerr = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

 if( (isset($_FILES['galleryField_1']) && $_FILES['galleryField_1']['error'] == 0)
    || (isset($_FILES['galleryField_2'])) 
        || (isset($_FILES['galleryField_3']))
            || (isset($_FILES['galleryField_4'])) 
   ){

        $allowedExts = array("JPEG", "jpeg", "jpg", "JPG");
        $temp = explode(".", $_FILES["galleryField_1"]["name"]);
        $extension = end($temp);

        if ((
           ($_FILES["galleryField_1"]["type"] == "image/JPEG")
        || ($_FILES["galleryField_1"]["type"] == "image/jpeg")
        || ($_FILES["galleryField_1"]["type"] == "image/jpg")
        || ($_FILES["galleryField_1"]["type"] == "image/JPG"))
        && in_array($extension, $allowedExts)){



            if($_FILES['galleryField_1']['size'] > 1048576) { //1 MB (size is also in bytes)

                $sizeerr = "Photo must be within 1 MB";

            } else{ 

              // Add this image into the database now

              $sql = mysql_query("INSERT INTO `shasthojito`.`sdispic` (`sdis_pic_id`, `pat_id`,        `comp_id`) VALUES (NULL, '$patient_id', '$complainID')") 
                   or die (mysql_error());

              $gallery_id = mysql_insert_id();
              // Place image in the folder 
              $newgallery = "$gallery_id.jpg";

              move_uploaded_file( $_FILES['galleryField_1']['tmp_name'], "dpic/$newgallery");

                }
        }else{
            $typeerr = "You have to put JPEG Image file";
        }
    }else{
            $imageerr = "No Image Selected";
    }

这里变量$ patientID工作正常并将数据传递给它,但$ complainID不能处理sql查询,但它在echo中显示值...

1 个答案:

答案 0 :(得分:1)

您正在GETPOST混合,因为您正在使用此行:

if ($_SERVER["REQUEST_METHOD"] == "POST") 

你需要改变这个:

if(isset($_GET["ComplainID"])){

$complainID = $_GET["ComplainID"];
}

要:

if(isset($_POST["ComplainID"])){

$complainID = $_POST["ComplainID"];
}

也许您只需要更改此内容:

if ($_SERVER["REQUEST_METHOD"] == "POST") 

要:

if ($_SERVER["REQUEST_METHOD"] == "GET") 

请确保您使用的方法将日期传输到实际文件。

编辑1:

通过上述评论回答您的问题,请更改此信息:

$sql = mysql_query("INSERT INTO `shasthojito`.`sdispic` (`sdis_pic_id`, `pat_id`,        `comp_id`) VALUES (NULL, '$patient_id', '$complainID')") 
                   or die (mysql_error());

要:

$sql = mysql_query("INSERT INTO `shasthojito`.`sdispic` (`sdis_pic_id`, `pat_id`,        `comp_id`) VALUES (NULL, '$patient_id', '".$complainID."')") 
                   or die (mysql_error());

编辑2:

在插入变量之前,请确保它与表格的comp_id列的类型相同:

if (isset($_GET['ComplainID']) && ctype_digit($_GET['ComplainID']))
{
  $complainID = $_GET["ComplainID"];
}