There is a table with monuments and their description, the script below displays all the names of the monuments in the form of links, so that when you click on the link (the name of the monument), a description of the monument that matches the name in the database is displayed

$opisanie= $_POST['opisanie']; $ima_pamytnika= $_POST['ima_pamytnika']; if(isset($_POST["send"])){ if(empty($_POST["opisanie"])) { $error[1] = 'Π²Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ Ρ„ΠΎΡ‚ΠΊΠΈ<br>'; } if(empty($_POST["ima_pamytnika"])) { $error[2] = 'Π²Π²Π΅Π΄ΠΈΡ‚Π΅ имя памятника<br>'; } if(!empty($error)) { foreach($error as $value) { echo 'Ошибка:'.$value; } }else{ $sql = "INSERT INTO pamyatniki(opisanie,name) VALUES ('$opisanie','$ima_pamytnika')"; mysql_query($sql) or die(mysql_error()); } } $res=mysql_query("SELECT name FROM pamyatniki ORDER BY id DESC"); while ($r = mysql_fetch_row($res)) { foreach ($r as $k => $d) { echo "памятник".' = <a href="">'.$d."</a><br/>"; } } // здСсь Π½Π΅ получаСтся вывСсти описаниС if(isset($d)){ $query=mysql_query("SELECT opisanie FROM pamyatniki WHERE name='$ima_pamytnika'"); while($row = mysql_fetch_array($query)) { echo $row['opisanie']; } } 
  • And where is the question? Another, not finished elementary school? - alexlz
  • Razzuy eyes in the code there is a comment // here it is impossible to display the description - LLIAKAJI
  • Dear Dunno, you are hardly ever trained in reading and writing. Razul eyes, see a comment, I do not see the question. And "here it is impossible to display a description" - a statement of fact, not a question. Moreover, the statement without clarification of what does not work, and what messages are displayed. - alexlz
  • dear znayka and how do you understand this scythe "you need that when you click on the link (name of the monument) a description of the monument is displayed which corresponds to the name in the database" + // it does not work here to output the description the output suggests itself to itself at the very end is not a working code, How to organize it for the correct work, which is described above, so the question is clearly asked? - LLIAKAJI
  • Absolutely incomprehensible. Your script for $ _POST ['opisanie'] = 'opisanie'; $ _POST ['ima_pamyatnika'] = 'name'; displays the monument = <a href=""> name </a> <br/> (meaningless enough, but so it is written in the script). What is wrong here - I do not understand. The result of "marginal" (from the word "attach") corresponds to the code. - alexlz

2 answers 2

 $opisanie= isset($_POST['opisanie']) ? $_POST['opisanie'] : null; $ima_pamytnika= isset($_POST['ima_pamytnika']) ? $_POST['ima_pamytnika'] : null; $isSend = isset($_POST["send"]) ? true : false; echo "1 OPISANIE: " . var_export($opisanie, true) . "<br/>"; echo "2 IMA_PAMYATNIKA: " . var_export($ima_pamytnika, true) . "<br/>"; echo "3 IS_SEND: " . ($isSend ? "TRUE" : "FALSE") . "<br/>"; if ($isSend) { $error = array(); if (empty($_POST["opisanie"])) { $error[] = 'Π²Π²Π΅Π΄ΠΈΡ‚Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ Ρ„ΠΎΡ‚ΠΊΠΈ<br>'; } if (empty($_POST["ima_pamytnika"])) { $error[] = 'Π²Π²Π΅Π΄ΠΈΡ‚Π΅ имя памятника<br>'; } if (count($error)) { echo "3_1 HAS ERRORS:<br/>"; foreach ($error as $value) { echo 'Ошибка:'.$value; } } else { $sql = "INSERT INTO pamyatniki(opisanie,name) VALUES ('$opisanie','$ima_pamytnika')"; echo "3_2 INSERT SQL: $sql<br/>"; $result = mysql_query($sql); if (!$result) { echo "3_3 INSERT ERROR: " . mysql_error() . "<br/>"; die(mysql_error()); } } } $res=mysql_query("SELECT name FROM pamyatniki ORDER BY id DESC"); echo "4 SELECT FROM PAMYATNIKI:<br/>"; while ($r = mysql_fetch_row($res)) { foreach ($r as $k => $d) { echo "памятник".' = <a href="">'.$d."</a><br/>"; } } // здСсь Π½Π΅ получаСтся вывСсти описаниС if (!isset($d)) { echo "5_0 !ISSET(d)<br/>"; die("GDE OPISANIE???"); } $sql = "SELECT opisanie FROM pamyatniki WHERE name='$ima_pamytnika'"; echo "5 SELECT SQL: $sql<br/>"; $query=mysql_query($sql); echo "6 QUERY RESULTS: " . var_export($query, true) . "<br/>"; while ($row = mysql_fetch_array($query)) { echo "7 CURRENT ROW: " . var_export($row, true) . "<br/>"; echo $row['opisanie']; } 

We insert it instead of your code and see what worked and what did not.

Since it is somehow incomprehensible at what point it breaks, I inserted the output after each action. Look at the output and say that it worked (by the output figures), which resulted.

You may have a table empty.

And another question - what description should be displayed? By code - the description of the last monument should be displayed, is this correct?

In general, report the results, then you can say something more accurately.

    One thing I can say for sure, it will be valuable advice to you and all PHP experts who are beginners:

    Before inserting any variables into the query, they need to be checked. Otherwise, everything can end very badly ...

    Interesting and useful article on wikipedia

    About this:

     if(isset($d)){ $query=mysql_query("SELECT opisanie FROM pamyatniki WHERE name='$ima_pamytnika'"); while($row = mysql_fetch_array($query)) { echo $row['opisanie']; } } 

    I don’t understand why to do while ... After all, mysql_fetch_array gets the first line that satisfies the conditions, and this line should be one. Then why cycle?

    Are you sure that your table has a column spelling opisanie?

    UPD: You can make a small debug, for this you can write in a prominent place

     echo ("SELECT opisanie FROM pamyatniki WHERE name='$ima_pamytnika'"); 

    Check whether what you see is the same as what you should see. And just in case, insert the result of the output into your sql admin panel (phpmyadmin most likely).

    • Before the implementation of the sql code is still far First you need to somehow earn, and only then build fences. What about while. One must be a string or not one - I do not know this. Suddenly not one? What then? - alexlz