I have the following code in php that does a search for all the columns within the table set
# list all columns from a table with a SHOW COLUMNS FROM
if(count($user_table_columns)) {
# If you have
foreach($_POST["contacts_form_a"] as $contacts_form_a => $form_a) {
# create two arrays, a changing the spaces to lines and putting everything in lowercase
# These viéram information to a form that the user can choose the names of the tables
$array_form_a[] = str_replace(" ", "_", strtolower($form_a));
$array_form_a_index[] = $form_a; }
foreach($user_table_columns as $user_columns => $columns) {
# create an array with all the table columns
$array_columns[] = str_replace(" ", "_", strtolower($columns["Field"]));
}
}
foreach($array_form_a as $index => $value) {
# Here it will check whether the data from the array in the array are two a
unset($checked);
if(in_array($value, $array_columns)) {
# compare the data of two arrays to create the condition
$checked = true;
}
if(isset($checked)) {
# If the column exists in the table, it inserts the information from the form
echo "INSERT INTO $usr_ ADD $value COMMENT " . $array_form_a_index[$index] . "<br>";
} else {
# If the column does not exist in the table, it creates the column after insert information
echo "ALTER TABLE $usr_ ADD $value COMMENT " . $array_form_a_index[$index] . "<br>";
/* insert into */
}
}
Is there a correct way to do this or this way is correct?
I wonder if there is how to improve this algorithm if it is in the wrong ways and or slow, for example, two arrays with the exchange of spaces for line and another without the Exchange and one that ensures the user writing and one that changes to the table, done in the right way?