Need help for Updating the mysql Table with PHP 8.2
Expecting mysql query for php 8.2
Hi friends,
I have a simple feedback form.
When the Send button is pressed, it will post the form data and update the feedback table.
Its working in PHP 7.4
When i have uploaded the code to cpanel, Its not updating the table.
Cpanel is having PHP version 8.1, 8.2 and 8.3
Can some body help me with the mysql query for php 8.2
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$mysql_server = 'localhost';
$mysql_database = 'db1';
$mysql_table = 'feedback';
$mysql_username = 'admin';
$mysql_password = 'password1';
$eol = "n";
if(isset($_POST['Send']))
{
$booknoworsave = $_POST['Send'];
}
global $booknoworsave;
if($booknoworsave == "Send")
{
foreach($_POST as $name=>$value)
{
$name = strtoupper($name);
$form_data[$name] = $value;
}
//create database
$conforbooknow = new mysqli($mysql_server, $mysql_username, $mysql_password);
mysqli_execute_query($conforbooknow, "CREATE DATABASE IF NOT EXISTS $mysql_database");
//create table
$conforbooknow =new mysqli($mysql_server, $mysql_username, $mysql_password, $mysql_database);
mysqli_execute_query($conforbooknow, "CREATE TABLE IF NOT EXISTS $mysql_table (ID int(9) NOT NULL auto_increment, `DATESTAMP` DATE, `TIME` VARCHAR(8) NOT NULL DEFAULT '00', `IP` VARCHAR(30) NOT NULL DEFAULT '00', `BROWSER` TINYTEXT, PRIMARY KEY (id))");
mysqli_execute_query($conforbooknow, "INSERT INTO $mysql_table (`DATESTAMP`, `TIME`, `IP`, `BROWSER`)
VALUES ('".date("Y-m-d")."',
'".date("G:i:s")."',
'".$_SERVER['REMOTE_ADDR']."',
'".$_SERVER['HTTP_USER_AGENT']."')");
//Update values
$id = mysqli_insert_id($conforbooknow);
foreach($form_data as $name=>$value)
{
$sql = "ALTER TABLE $mysql_table ADD $name VARCHAR(50) NOT NULL DEFAULT '00'";
$conforbooknow->query($sql);
}
foreach($form_data as $name=>$value)
{
$sql = "UPDATE $mysql_table SET $name = '$value' WHERE id = '$id'";
$conforbooknow->query($sql);
}
}//Add new item
}
?>
New contributor
Murugan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
8