gpt4 book ai didi

php - MySQL所有变量不传递数据

转载 作者:行者123 更新时间:2023-11-29 00:06:13 25 4
gpt4 key购买 nike

我在向 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 中显示值 ...

最佳答案

您将 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"];
}

关于php - MySQL所有变量不传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27332945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com