Hello, help solve the problem gives this error when starting the page:

Undefined index: id_topic in C:\wamp64\www\forum1\view_topic.php on line 42 

Although this name is in the table and I want to take its id and display its value by the given id. Here is the code located on 42 lines:

 $id = $_GET['id_topic']; $sql = "SELECT * FROM $tbl_name WHERE id_topic='$id'"; $result = mysqli_query($con, $sql) or die(mysqli_error()); if ($rows = mysqli_fetch_array($result)) { //значения из таблицы через $rows } 

I use php7 and help me figure it out. Mysql table:

 CREATE TABLE `forum_question` ( `id_topic` int(31) NOT NULL, `topic` varchar(255) NOT NULL, `detail` longtext NOT NULL, `name` varchar(255) NOT NULL, `email` varchar(31) NOT NULL, `date` varchar(31) NOT NULL, `view` int(31) NOT NULL, `reply` int(31) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
  • Show the listing view_topic.php if it is not very big) - Kirill Korushkin
  • 3
    $ id = $ _GET ['id_topic']; Here you have an error, there is no value in the array with such an index. It is possible that you do not correctly pass the parameters to GET, check - quaresma89
  • Show the form or what does this get run there for you? Or copy and bring here from the address bar - n.osennij
  • The file itself is drive.google.com/open?id=0BzuVepyc1IA5clNManlpdUF0MkE - Eldos Kadyrkul
  • @ EldosKadyrkul Tak. Show me what you have in the address bar when you go to this page and this error appears. Just copy the whole address and send it here - n.osennij

2 answers 2

The problem is not whether you have such a line in the database, but that you do not pass the line number to the URL of the page.

If you want to get id here

 $id = $_GET['id_topic']; 

That page address should be:

http://yoursite.ru/path/toscript.php ? id_topic = 42

Then

 $id = $_GET['id_topic']; //id теперь 42. 

    Specifically, on your question you need to check the installation in the variable $ _GET ['id_topic'] of any value

    those.

     if (isset($_GET['id_topic'])) { $id = $_GET['id_topic']; .... <?php } ?> 

    But in fact, this is a half-measure just a cleaning error.

    It is also necessary to do another error handler if $ _GET ['id_topic'] is not specified (for example, to display "The subject with such ID is not found"), and id_topic may not exist in the database.

    It is also advisable to test the entire script for links without such a GET parameter, i.e. all links leading to this page should contain id_topic = (number) in the address bar