Home>

I try to just get the last ID with the 'Insert_id', and I looked at how to do it
here ( https://www.w3schools.com/php/php_mysql_insert_lastid.asp), but I write id= 0
Maybe now something else needs to receive the last ID, I just don't understand
Why this method does not work, here is my code if that ↓

<
? php.
                    $ ServerName= "Localhost";
                    $ username= "root";
                    $ password= "";
                    $ dbname= "pocztadb";
                    $ WLASCICIEL= $ _session ["Nick"];
                    $ Conn= New MySqli ($ ServerName, $ username, $ password, $ dbname);
                    if ($ Conn->
Connect_error) {
                        DIE ("Connection Failed:". $ Conn->
Connect_error);
                    }
                    //here I'm trying to get it ↓
                    $ Last_ID= $ Conn->
INSERT_ID;
                    $ SQL= "SELECT * from Wiadomosci Where Wlasciciel= '$ Wlasciciel' and
                            KATALOG= 'ODEBRANE' AND ID >
 $ Last_ID Order by Data ";
                    $ result= $ Conn->
Query ($ SQL);
                    if ($ result->
num_rows >
 0) {
                    //Here I disable and I write "Last id= 0" ↓
                    Echo "<
H1 >
Last id= ". $ Last_ID." <
/h1 >
";
                } ELSE {
                    Echo "BRAK";
                }
                        $ Conn->
close ();
          ? ≫

After the request to the database it receives, and not before. And in general it refers to INSERT

Jean-Claude2021-06-05 19:08:56

To get a Last_ID, you must first execute the request from INSERT. What you in the code are trying to do -a mystery.

Vladimir Gonchar2021-06-05 21:59:28