0

My php script doesn't work (no entries are added) while my others scripts work, they are different but similar, only the values and fields are different. Does anyone know why? The form part works, my values are correct but there are no new entries in my database and no errors are reported.

if(isset($_POST['id_discord']) AND !empty($_POST['id_discord'])) {
        try {
        $bdd = new PDO('mysql:host=localhost:3306;dbname=teg;charset=utf8', 'username', 'password');
        }
        catch (Exception $e){
            die('Erreur : ' . $e->getMessage());
        }

        $req = $bdd->prepare('INSERT INTO staff(id_discord, pseudo_discord, discord_tag, pseudo_mc, UUID, rank, rank_level, description, twitter, youtube, twitch, instagram) VALUES (:id_discord, :pseudo_discord, :discord_tag, :pseudo_mc, :UUID, :rank, :rank_level, :description, :twitter, :youtube, :twitch, :instagram);') or die(print_r($bdd->errorInfo()));;
        $req->execute(array(
            'id_discord' => $_POST['id_discord'],
            'pseudo_discord' => $_POST['pseudo_discord'],
            'discord_tag' => '#' . $_POST['discord_tag'],
            'pseudo_mc' => $_POST['pseudo_mc'],
            'UUID' => $_POST['UUID'],
            'rank' => $_POST['rank'],
            'rank_level' => $_POST['rank_level'],
            'description' => $_POST['description'],
            'twitter' => $_POST['twitter'],
            'youtube' => $_POST['youtube'],
            'twitch' => $_POST['twitch'],
            'instagram' => $_POST['instagram']
        ));
    }

This is another script for another form and it works, but they are the same, only values and fields are different

if(isset($_POST['numero']) AND !empty($_POST['numero'])) {
        try {
        $bdd = new PDO('mysql:host=localhost:3306;dbname=teg;charset=utf8', 'username', 'password');
        }
        catch (Exception $e){
            die('Erreur : ' . $e->getMessage());
        }

        $req = $bdd->prepare('INSERT INTO kiosque(numero, date_publication, description, edition, calameo, reading_time) VALUES (:numero, :date_publication, :description, :edition, :calameo, :reading_time);') or die(print_r($bdd->errorInfo()));;
        $req->execute(array(
            'numero' => $_POST['numero'],
            'date_publication' => $_POST['date_publication'],
            'description' => $_POST['description'],
            'edition' => $_POST['edition'],
            'calameo' => $_POST['calameo'],
            'reading_time' => $_POST['reading_time']));

        /* Form files */
        if (isset($_FILES['pdf']['tmp_name'])) {
            $destination = '/var/www/vhosts/theelderguardian.fr/httpdocs/resources/kiosque/';
            $entire_path = $destination . $_POST['edition'] . '.pdf';
            // move_uploaded_file($_FILES['pdf']['tmp_name'], $destination.$_FILES['pdf']['name']);
            rename($_FILES['pdf']['tmp_name'], $entire_path);
            chmod($entire_path, 0644);
        }

        if (isset($_FILES['first_page']['tmp_name'])) {
            $destination = '/var/www/vhosts/theelderguardian.fr/httpdocs/resources/kiosque/';
            $entire_path = $destination . $_POST['edition'] . '.png';
            // move_uploaded_file($_FILES['pdf']['tmp_name'], $destination.$_FILES['pdf']['name']);
            rename($_FILES['first_page']['tmp_name'], $entire_path);
            chmod($entire_path, 0644);  
        }

        if (isset($_FILES['thumbnail']['tmp_name'])) {
            $destination = '/var/www/vhosts/theelderguardian.fr/httpdocs/resources/kiosque/';
            $entire_path = $destination . $_POST['edition'] . '_thumbnail.png';
            // move_uploaded_file($_FILES['pdf']['tmp_name'], $destination.$_FILES['pdf']['name']);
            rename($_FILES['thumbnail']['tmp_name'], $entire_path);
            chmod($entire_path, 0644);
        }
    }
  • 1
    What version of mysql? Could be `rank` being used because it is reserved, https://dev.mysql.com/doc/refman/8.0/en/keywords.html.. use backticks on it if that is the case – user3783243 Apr 28 '21 at 21:35
  • _"...no new entries in my database and no errors are reported"_ is just not possible. It may simply be a matter of you not seeing the errors. Check out [My PDO statement doesn't work](https://stackoverflow.com/questions/32648371/my-pdo-statement-doesnt-work) for some tips on finding out the error. Unless this code isn't executing at all - have you verified that it's reached? – El_Vanja Apr 28 '21 at 22:04
  • On a little side note: `isset` is not necessary when checking `!empty`. Empty will check if the variable is set. – El_Vanja Apr 28 '21 at 22:07
  • 1
    `rank` and `description` are both keywords in MySQL 8.02+. If you want to use them as column names you'll have to wrap them in backticks. See https://dev.mysql.com/doc/refman/8.0/en/keywords.html – Tangentially Perpendicular Apr 28 '21 at 22:10
  • Yes, best to always quote table names in backticks to avoid problems. – miken32 Apr 28 '21 at 22:29
  • Also you should stick to a consistent method for managing errors. `try`/`catch` and `die()` are very different things. But in no case should you be showing errors to your users. – miken32 Apr 28 '21 at 22:30

0 Answers0