Help me please! No data is added to the table, although the page says that the data was successfully added. In phpmyadmin is not available the Browse section says that it is empty. What is it I do not understand? the table has 5 columns

GREATE TABLE guitarwars ( date DATETIME , name VARCHAR (30) , score DEC (10,0) screenshot VARCHAR (64) ); 

Then added id.

 <?php //Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΡ константы, содСрТащиС имя ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π° //Для Π·Π°Π³Ρ€ΡƒΠΆΠ°Π΅ΠΌΡ‹Ρ… Ρ„Π°ΠΉΠ»ΠΎΠ² ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ define('GW_UPLOADPATH', 'images/'); if (isset($_POST['submit'])) { //ΠΈΠ·Π²Π»Π΅Ρ‡Π΅Π½ΠΈΠ΅ Π΄Π°Π½Π½Ρ‹Ρ… ΠΈΠ· ΡΡƒΠΏΠ΅Ρ€Π³Π»ΠΎΠ±Π°Π»ΡŒΠ½ΠΎΠ³ΠΎ массива $_POST $name = $_POST['name']; $score = $_POST['score']; $screenshot = $_FILES['screenshot']['name']; if (!empty($name) && !empty($score) && !empty($screenshot)) { //ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅ Ρ„Π°ΠΉΠ»Π° Π² постоянный ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ для Ρ„Π°ΠΉΠ»ΠΎΠ² ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ $target = GW_UPLOADPATH . $screenshot; if (move_uploaded_file($_FILES['screenshot'] ['tmp_name'], $target)) { //соСдинСниС с Π±Π°Π·ΠΎΠΉ Π΄Π°Π½Π½Ρ‹Ρ… $dbc = mysqli_connect('localhost', '', '', 'r0058300_arty21'); //Π—Π°ΠΏΠΈΡΡŒ Π΄Π°Π½Π½Ρ‹Ρ… Π² Π±Π°Π·Ρƒ Π΄Π°Π½Π½Ρ‹Ρ… $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score' '$screenshot')"; mysqli_query($dbc, $query); //Π’Ρ‹Π²ΠΎΠ΄ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŽ потвСрТдСния Π² ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠΈ Π΄Π°Π½Π½Ρ‹Ρ… echo '<p>Бпасибо Π·Π° Ρ‚ΠΎ, Ρ‡Ρ‚ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΠ»ΠΈ свой Π½ΠΎΠ²Ρ‹ΠΉ Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³!</p>'; echo '<p><strong>Имя:</strong> ' . $name . '<br/>'; echo '<strong>Π Π΅ΠΉΡ‚ΠΈΠ½Π³:</strong> ' . $score . '<br/>'; echo '<img src"' . GW_UPLOADPATH . $screenshot . '" alt="Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ , ΠΏΠΎΠ΄Ρ‚Π²Π΅Ρ€ΠΆΠ΄Π°ΡŽΡ‰Π΅Π΅ ΠΏΠΎΠ΄Π»ΠΈΠ½ΠΎΡΡ‚ΡŒ Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³Π°" /><p />'; echo '<p><a href="index.php">&lt;&lt; Назад ΠΊ списку Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³ΠΎΠ²</a></p>'; //ΠžΡ‡ΠΈΡΡ‚ΠΊΠ° ΠΏΠΎΠ»Π΅ΠΉ Π²Π²ΠΎΠ΄Π° Π΄Π°Π½Π½Ρ‹Ρ… Ρ„ΠΎΡ€ΠΌΡ‹ $name = ""; $score = ""; $screenshot = ""; mysqli_close($dbc); } else { echo '<p class="error">Π’Π²Π΅Π΄ΠΈΡ‚Π΅, поТалуйста, всю ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡƒΡŽ ' . 'для добавлСния вашСго Ρ€Π΅ΠΉΡ‚ΠΈΠ½Π³Π°.</p>'; } 

}

}?>

I have a suspicion that problems with this part of the code

 $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score' '$screenshot')"; mysqli_query($dbc, $query); 

    2 answers 2

    Try to check the connection itself and run the query: http://ir2.php.net/mysqli_query

    I suspect a problem in connecting to the database.

     <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if ($result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT)) { /* Note, that we can't execute any functions which interact with the server until result set was closed. All calls will return an 'out of sync' error */ if (!$mysqli->query("SET @a :='this will not work'")) { printf("Error: %s\n", $mysqli->error); } $result->close(); } 

      Connection problem, you have already been answered above.

      • the answer could be left) - IVsevolod
      • but when adding information, the page does not swear at the connection, but on the contrary writes that all ok data is added. If there were problems with the connection then, logically, the browser would swear! Or am I wrong? - Arty21