1

I am facing a problem with send variable data to mysql, one of my variable is passing but other is not.

<?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";
    }

Here the variable $patientID is working fine and passing the data into it, but the $complainID is not working on sql query but its showing the value in echo ...

mhtamun
  • 65
  • 1
  • 12

1 Answers1

1

Your are mixing GET with POST Since you're using this line:

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

You need to change this:

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

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

To:

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

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

Or maybe you only need to change this:

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

To:

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

Be sure about the method you are using to transfer date to your actual file.

EDIT 1:

Following your answers through your comments above, please change this:

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

To:

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

EDIT 2:

Before inserting the variable, be sure it is of the same type as the column comp_id of your table:

if (isset($_GET['ComplainID']) && ctype_digit($_GET['ComplainID']))
{
  $complainID = $_GET["ComplainID"];
}
  • @mhtamun in that case perform the second change I mentioned (after **Or**) –  Dec 06 '14 at 15:25
  • @mhtamun so you receive that variable from URL and you are able to echo it after GETting it ? –  Dec 06 '14 at 15:28
  • @mhtamun Ok, I understand better your problem now. Can you tell me please what is the type of `comp_id`` in your table (database) ? –  Dec 06 '14 at 15:30
  • interger type length 11 in mysql – mhtamun Dec 06 '14 at 15:33
  • @mhtamun do you get any error ? if yes, can you display it please ? (the error from your original code) –  Dec 06 '14 at 16:13
  • @mhtamun strange ... what about if you remove that long white space in your query before `comp_id` ? –  Dec 06 '14 at 16:28