How to extract a data from an array in php

0

Good people, well my little script for posts checks if it already exists, if yes it does not record, if not it writes to bd. I want to put a tanned system in it, so I created a table but for me to identify the post and I need the ID of the post .. So that's alright .. If you look at the "print_r ($ idcheck);" it returns an array with the id and the post, but I get to extract the id as a string, but for my lack of knowledge until I could not solve it ..

Array (     [0] = > Array         (             [id] = > 62             [content] = > jjjjjjjjjjjjjjjjjjj         ) ) I need only the id, but when I put echo $ idcheck ["id"] or idcheck [0] of the error ..         

        $status = 1;

        if( isset( $_POST['publicar'] ) ){

            date_default_timezone_set('America/Sao_Paulo');
            $form['data']       = date('Y-m-d H:i:s');
            $form['conteudo']   = str_replace( '\r\n', "\n", DBEscape( trim( $_POST['conteudo'] ) ));
            $form['status']     = DBEscape( strip_tags( trim( $status ) ) );
            if( empty( $form['conteudo'] ) )
                echo'';
            else {

                $dbCheck = DBRead( 'posts', "WHERE conteudo = '". $form['conteudo'] ."'" );

                if( $dbCheck )
                    echo '<script>alert("Desculpe, mas já contaram esse segredo!");</script>';
                else {

                    if( DBCreate( 'posts', $form ) ){
                        $idcheck = DBRead( 'posts', "WHERE conteudo = '". $form['conteudo'] ."'", 'id, conteudo');  
                        var_dump($idcheck);
                        echo '<pre>';
                        print_r($idcheck);
                        echo '</pre>';
                        //echo '<script>document.getElementById("myP").style.visibility = "visible";</script>';
                        echo '<script>alert("Seu segredo foi postado com sucesso!");</script>';
                    }
                    else
                        echo '<script>alert("Desculpe, ocorreu um erro...");</script>';
                }
            }

        }
?>
    
asked by anonymous 06.07.2016 / 02:00

1 answer

0

Try the following:

$id = (string)$idcheck[0]['id'];

From what I've seen, this $ idcheck variable is a multidimensional array. I also suggested forcing the value to string, to make sure that the $ id variable will get the value as string.

    
06.07.2016 / 02:07