Having problems with form on higher php version

Issues related to forms.
Post Reply
wwonderfull
 
 
Posts: 1305
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Having problems with form on higher php version

Post by wwonderfull »

On php 7.3 or 7.4 the form works fine but on php 8 or 8.1, 8.2 it gets errors.

It was not the issue with hostinger. I tested using xammp php 8.2.4 the same errors came. So I think it has to be something related to php.ini config I think. I have given the project file and also the php.ini file. I tested it with both online mysql and even xammp localhost.

Note that the first time the form will submit correctly but when the second time the form again gets submitted the Uncaught mysqli_sql_exception: Duplicate column name 'FORMID'

There are other issues which I have written in the notes in the project file.

here are the files
https://temp-file.org/NlP6dn5dkuKoCl2/file
User avatar
Pablo
 
Posts: 21836
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Having problems with form on higher php version

Post by Pablo »

I do not see any issues in form.
This sounds like a database configuration issue.

Maybe you have accidentally set the formid field of the MYSQL table as primary key?
Or maybe the 'formid' field exists twice?
wwonderfull
 
 
Posts: 1305
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: Having problems with form on higher php version

Post by wwonderfull »

Pablo wrote: Sun Aug 06, 2023 9:57 am I do not see any issues in form.
This sounds like a database configuration issue.

Maybe you have accidentally set the formid field of the MYSQL table as primary key?
Or maybe the 'formid' field exists twice?
As I said the form works fine in php 7.3 or 7.4 no errors everything is fine.
Maybe you have accidentally set the formid field of the MYSQL table as primary key?
No. Everything is done automatically nothing in the mysql database is configured. All is done automatically when the form submits the columns get created the primary key is ID

dbtest InnoDB utf8mb4_general_ci 16.0 KiB

# Name Type Collation Attributes Null Default Comments Extra Action
1 ID (P_KEY) int(9) No None AUTO_INCREMENT Change Change Drop Drop
2 DATESTAMP date Yes NULL Change Change Drop Drop
3 TIME varchar(8) utf8mb4_general_ci Yes NULL Change Change Drop Drop
4 IP varchar(15) utf8mb4_general_ci Yes NULL Change Change Drop Drop
5 BROWSER tinytext utf8mb4_general_ci Yes NULL Change Change Drop Drop
6 FORMID varchar(255) utf8mb4_general_ci Yes NULL Change Change Drop Drop
7 NAME varchar(255) utf8mb4_general_ci Yes NULL Change Change Drop Drop
8 EMAIL varchar(255) utf8mb4_general_ci Yes NULL Change Change Drop Drop
9 MESSAGE varchar(255) utf8mb4_general_ci Yes NULL Change Change Drop Drop

Or maybe the 'formid' field exists twice?
As I had said previously the first time the form will submit correctly but when the second time the form again gets submitted the Uncaught mysqli_sql_exception: Duplicate column name 'FORMID'. I think that means on php 8 they dont let the FORMID loop happen because it already exists so no need to create or place the same column it again.

The error encountering is due to the attempt to add a duplicate column name 'FORMID' to the MySQL table. It seems that the 'FORMID' column is already present in the table because on every submit the form trys to create already created column again like replacing, and the code is trying to add it again, leading to the duplicate column error.

In the provided code, the 'FORMID' column is not explicitly added through the loop that processes form data. Instead, it seems to be added implicitly with the other form field names. Since the 'FORMID' key is part of the $_POST array, it is processed in the loop with other form fields, causing the error.

I think the script needs to be edited for a better compatibility for php 8, because php 7 did not have these issues.
User avatar
Pablo
 
Posts: 21836
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Having problems with form on higher php version

Post by Pablo »

Instead, it seems to be added implicitly with the other form field names.
What difference does that make?
Since the 'FORMID' key is part of the $_POST array, it is processed in the loop with other form fields, causing the error.
Why do you think that? It's just a form field like all others!
wwonderfull
 
 
Posts: 1305
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: Having problems with form on higher php version

Post by wwonderfull »

Running out of reasons why it is happening. A form which perfectly works on php 7 why doesn't it work on php 8. No settings are changed. The script is fine as long as it is having problem with the php configuration I guess.

how did the form work for you @pablo did you use mysql database with attachment and smtp meaning all in all? Did the success page show on php 8.2? Did you use the php.ini file I provided? Do I need to configure it again with any changes?
User avatar
Pablo
 
Posts: 21836
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Having problems with form on higher php version

Post by Pablo »

Your form works for me with php 8.x. The file is uploaded and the entry in the databases is created. It works multiple times. No errors.
Obviously I had to change the STMP and MySQL settings to make it work for me.

I have tested it on 2 different hosting servers: strato.com (PHP 8.1) and ionos.com(PHP 8.2)

I did not use your php.ini, because that does not work on my webhost.

I really do not understand the message 'Uncaught mysqli_sql_exception: Duplicate column name 'FORMID'
message because there is only one Form ID in the form.

To me this sounds like there is an issue on the server side.

Update:
I have found this related information: https://php.watch/versions/8.1/mysqli-error-mode

So, you can try to add this code via Page HTML (start of page)

Code: Select all

<?php
mysqli_report(MYSQLI_REPORT_OFF);
?>
wwonderfull
 
 
Posts: 1305
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: Having problems with form on higher php version

Post by wwonderfull »

That did not work. But guess what, I got to know what is the reason of the error :D I tested for a long time checking unchecking many things to be more exact.

PHP 8.0 Hostinger
The database gets the data and I even get the email

All the reason of the problem is because of the file upload. I unchecked [X] UPLOAD FILES TO FOLDER ON THE SERVER and everything is fine. So this seems to be the problem nothing else. But I do want to use this feature as I want to upload my files on a folder on the server. But I will get that error if I do. I hope there can be a fix for it.

My upload folders name was uploads_mysitename and the file size was 22000 meaning 22MB that's all I had on options
User avatar
Pablo
 
Posts: 21836
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Having problems with form on higher php version

Post by Pablo »

For me, your project also works with file uploads. I have tested yesterday almost all day on several different servers.
wwonderfull
 
 
Posts: 1305
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: Having problems with form on higher php version

Post by wwonderfull »

Latest update 18.3.2 fixed everything @pablo. The form now works on every php version including PHP 8.2.4. I tested in xammp, hostinger all success. Marvelous solution you have provided :D 🎉
Post Reply