Re: Email form not working on new server
Posted: Tue Aug 01, 2023 2:24 pm
I did a test and this is what my php error log shows on hostinger with php version 8.2
[01-Aug-2023 ] PHP Warning: Undefined variable $upload_FieldName in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 ] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /home/domains/mywebsite.com/public_html/index.php:229
Stack trace:
#0 {main}
thrown in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 ] PHP Warning: Undefined variable $upload_FieldName in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 ] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /home/domains/mywebsite.com/public_html/index.php:229
Stack trace:
#0 {main}
thrown in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 13:53:47 UTC] PHP Fatal error: Uncaught mysqli_sql_exception: Duplicate column name 'FORMID' in /home/domains/mywebsite.com/public_html/index.php:242
Stack trace:
#0 /home/domains/mywebsite.com/public_html/index.php(242): mysqli_query()
#1 {main}
thrown in /home/domains/mywebsite.com/public_html/index.php on line 242
and below is the code which it was referring to which I think is the php script for the form.
$mail->CharSet = 'UTF-8';
$mail->WordWrap = 80;
$mail->Body = $message;
$mail->Send();
$search = array("ä", "Ä", "ö", "Ö", "ü", "Ü", "ß", "!", "§", "$", "%", "&", "/", "\x00", "^", "°", "\x1a", "-", "\"", " ", "\\", "\0", "\x0B", "\t", "\n", "\r", "(", ")", "=", "?", "`", "*", "'", ":", ";", ">", "<", "{", "}", "[", "]", "~", "²", "³", "~", "µ", "@", "|", "<", "+", "#", ".", "´", "+", ",");
$replace = array("ae", "Ae", "oe", "Oe", "ue", "Ue", "ss");
foreach($_POST as $name=>$value)
{
$name = str_replace($search, $replace, $name);
$name = strtoupper($name);
if (is_array($value))
{
$form_data[$name] = implode(",", $value);
}
else
{
$form_data[$name] = $value;
}
}
#229 for ($i = 0; $i < count($upload_FieldName); $i++)
{
$name = str_replace($search, $replace, $upload_FieldName[$i]);
$name = strtoupper($name);
$form_data[$name] = $upload_URL[$i];
}
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password) or die('Failed to connect to database server!<br>'.mysqli_error($db));
mysqli_set_charset($db, 'utf8');
mysqli_query($db, "CREATE DATABASE IF NOT EXISTS $mysql_database");
mysqli_select_db($db, $mysql_database) or die('Failed to select database<br>'.mysqli_error($db));
mysqli_query($db, "CREATE TABLE IF NOT EXISTS $mysql_table (ID int(9) NOT NULL auto_increment, `DATESTAMP` DATE, `TIME` VARCHAR(8), `IP` VARCHAR(15), `BROWSER` TINYTEXT, PRIMARY KEY (id))");
foreach($form_data as $name=>$value)
{
#242 mysqli_query($db ,"ALTER TABLE $mysql_table ADD $name VARCHAR(255)");
}
mysqli_query($db, "INSERT INTO $mysql_table (`DATESTAMP`, `TIME`, `IP`, `BROWSER`)
VALUES ('".date("Y-m-d")."',
'".date("G:i:s")."',
'".$_SERVER['REMOTE_ADDR']."',
'".$_SERVER['HTTP_USER_AGENT']."')")or die('Failed to insert data into table!<br>'.mysqli_error($db));
$id = mysqli_insert_id($db);
foreach($form_data as $name=>$value)
{
mysqli_query($db, "UPDATE $mysql_table SET $name='".mysqli_real_escape_string($db, $value)."' WHERE ID=$id") or die('Failed to update table!<br>'.mysqli_error($db));
}
mysqli_close($db);
$successcode = file_get_contents($success_url);
$successcode = ReplaceVariables($successcode);
echo $successcode;
}
catch (Exception $e)
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $e->getMessage(), $errorcode);
echo $errorcode;
}
exit;
}
?>
[01-Aug-2023 ] PHP Warning: Undefined variable $upload_FieldName in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 ] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /home/domains/mywebsite.com/public_html/index.php:229
Stack trace:
#0 {main}
thrown in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 ] PHP Warning: Undefined variable $upload_FieldName in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 ] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /home/domains/mywebsite.com/public_html/index.php:229
Stack trace:
#0 {main}
thrown in /home/domains/mywebsite.com/public_html/index.php on line 229
[01-Aug-2023 13:53:47 UTC] PHP Fatal error: Uncaught mysqli_sql_exception: Duplicate column name 'FORMID' in /home/domains/mywebsite.com/public_html/index.php:242
Stack trace:
#0 /home/domains/mywebsite.com/public_html/index.php(242): mysqli_query()
#1 {main}
thrown in /home/domains/mywebsite.com/public_html/index.php on line 242
and below is the code which it was referring to which I think is the php script for the form.
$mail->CharSet = 'UTF-8';
$mail->WordWrap = 80;
$mail->Body = $message;
$mail->Send();
$search = array("ä", "Ä", "ö", "Ö", "ü", "Ü", "ß", "!", "§", "$", "%", "&", "/", "\x00", "^", "°", "\x1a", "-", "\"", " ", "\\", "\0", "\x0B", "\t", "\n", "\r", "(", ")", "=", "?", "`", "*", "'", ":", ";", ">", "<", "{", "}", "[", "]", "~", "²", "³", "~", "µ", "@", "|", "<", "+", "#", ".", "´", "+", ",");
$replace = array("ae", "Ae", "oe", "Oe", "ue", "Ue", "ss");
foreach($_POST as $name=>$value)
{
$name = str_replace($search, $replace, $name);
$name = strtoupper($name);
if (is_array($value))
{
$form_data[$name] = implode(",", $value);
}
else
{
$form_data[$name] = $value;
}
}
#229 for ($i = 0; $i < count($upload_FieldName); $i++)
{
$name = str_replace($search, $replace, $upload_FieldName[$i]);
$name = strtoupper($name);
$form_data[$name] = $upload_URL[$i];
}
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password) or die('Failed to connect to database server!<br>'.mysqli_error($db));
mysqli_set_charset($db, 'utf8');
mysqli_query($db, "CREATE DATABASE IF NOT EXISTS $mysql_database");
mysqli_select_db($db, $mysql_database) or die('Failed to select database<br>'.mysqli_error($db));
mysqli_query($db, "CREATE TABLE IF NOT EXISTS $mysql_table (ID int(9) NOT NULL auto_increment, `DATESTAMP` DATE, `TIME` VARCHAR(8), `IP` VARCHAR(15), `BROWSER` TINYTEXT, PRIMARY KEY (id))");
foreach($form_data as $name=>$value)
{
#242 mysqli_query($db ,"ALTER TABLE $mysql_table ADD $name VARCHAR(255)");
}
mysqli_query($db, "INSERT INTO $mysql_table (`DATESTAMP`, `TIME`, `IP`, `BROWSER`)
VALUES ('".date("Y-m-d")."',
'".date("G:i:s")."',
'".$_SERVER['REMOTE_ADDR']."',
'".$_SERVER['HTTP_USER_AGENT']."')")or die('Failed to insert data into table!<br>'.mysqli_error($db));
$id = mysqli_insert_id($db);
foreach($form_data as $name=>$value)
{
mysqli_query($db, "UPDATE $mysql_table SET $name='".mysqli_real_escape_string($db, $value)."' WHERE ID=$id") or die('Failed to update table!<br>'.mysqli_error($db));
}
mysqli_close($db);
$successcode = file_get_contents($success_url);
$successcode = ReplaceVariables($successcode);
echo $successcode;
}
catch (Exception $e)
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $e->getMessage(), $errorcode);
echo $errorcode;
}
exit;
}
?>