1

I am trying to upload some images to my database with some data, when I do this in localhost it's all work fine. But on the server, only some queries work fine. but others are not working.

This is my database pages table and papertag table

CREATE TABLE `pages` 
(
    `pageId` int(10) NOT NULL, 
    `paperId` varchar(255) NOT NULL, 
    `filePath` varchar(255) NOT NULL, 
    `fileType` varchar(20) NOT NULL,
    `status` enum('0','1') NOT NULL,
    `dateAndTime` datetime NOT NULL,
    `description` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `pages`
--
ALTER TABLE `pages`
  ADD PRIMARY KEY (`pageId`), 
  ADD KEY `paperId` (`paperId`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `pages`
--
ALTER TABLE `pages`
  MODIFY `pageId` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=324;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `pages`
--
ALTER TABLE `pages`
  ADD CONSTRAINT `pages_ibfk_1` FOREIGN KEY (`paperId`) REFERENCES `papers` (`paperId`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;

-----paper tag------

CREATE TABLE `papertag` 
(
    `tagId` int(11) NOT NULL,
    `paperId` varchar(255) NOT NULL,
    `tagName` varchar(255) NOT NULL,
    `des` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `papertag`
--
ALTER TABLE `papertag`
  ADD PRIMARY KEY (`tagId`),
  ADD KEY `paperId` (`paperId`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `papertag`
--
ALTER TABLE `papertag`
  MODIFY `tagId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=460;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `papertag`
--


 ALTER TABLE `papertag`
      ADD CONSTRAINT `papertag_ibfk_1` FOREIGN KEY (`paperId`) REFERENCES `papers` (`paperId`) ON DELETE CASCADE ON UPDATE CASCADE;
    COMMIT;

and this is my SQL query code in PHP file

$up22 = mysqli_query($connection, "INSERT INTO papertag(`paperId`, `tagName`) VALUES ('{$paperId}', '{$nme}')");


$up = mysqli_query($connection, "INSERT INTO pages(`paperId`, `filePath`, `fileType`, `status`, `dateAndTime`) VALUES ('{$paperId}', '{$img_dir}', '{$type}',2 , '{$date}' )");
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 2
    You should learn to use prepared statements with parameters instead of substituting variables into your query strings. You should also add error checking so you see the reason why queries don't work. https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments – Barmar Oct 30 '19 at 05:22
  • What error are you getting? Also can you make sure that both are using same version of mysql? – Md. Mahmud Hasan Oct 30 '19 at 05:47
  • maybe you must replace '{$paperId}' to {$paperId} because of the type of number – rezaSefiddashti Nov 28 '21 at 06:21

1 Answers1

0

I think you have to insert all columns with not null Constraint. you did not insert des column for example. you need this code :

$up22 = mysqli_query($connection, "INSERT INTO papertag(`paperId`, `tagName`,`des`) VALUES ('{$paperId}', '{$nme}'),'{$des}'");
rezaSefiddashti
  • 134
  • 1
  • 9