-1

I have this code:

<html>
<head>
<meta charset="utf-8">
</head>
<body>
Wpisz ucznia

<form method="POST">
<input type="text" name="nazwisko" /> Nazwisko<br>
<input type="text" name="imie" /> Imie<br>
<input type="text" name="srednia"/>Średnia ocen  <br>
<input type="text" name="idklasy"/> idklasy <br>
<input type="submit" name="wpisz" value="Dodaj">
</form>
<?php
$baza=mysqli_connect("localhost","root","","szkoła") or die("Wystąpił błąd połączenia z bazą");

if(isset($_POST["wpisz"]))
{
    $nazwisko=$_POST['nazwisko'];
    $imie=$_POST['imie'];
    $srednia=$_POST['srednia'];
    $idklasy=$_POST['idklasy'];
    $wstaw="INSERT INTO uczen ('Nazwisko','Imie','Srednia_ocen','id_klasy') VALUES ('$nazwisko','$imie','$srednia','$idklasy)";
    $wynik= mysqli_query($baza,$wstaw);
    if($wynik)
    echo "Rekord został dodany poprawnie";
    else
        echo "Błąd, nie udało się dodać nowego rekordu" ;
}
$kw="select * from uczen";
$niewynik =mysqli_query ($baza,$kw);
$liczba=mysqli_num_rows($niewynik);
echo "<br>
Obecnie w szkole jest ".$liczba." uczniów.";

?>
</body>
</html>

and for some reason that insert don't want work. I checked few sites and any of their solutions didn't helped.

esqew
  • 42,425
  • 27
  • 92
  • 132
Robix
  • 1
  • 1
    Welcome to Stack Overflow! Unfortunately, your question is lacking in details and is likely to be put On Hold/closed as it's currently written. Please edit your question to include a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Additionally, the statements "*that insert don't want work*" and "*I checked a few sites and any of their solutions didn't helped*" are both unclear and don't assist potential answerers. Instead, include information on *how* you know it doesn't work, including all error messages as well as expected vs. actual behaviors. – esqew Nov 19 '20 at 15:41
  • 1
    You may also be interested in re-visiting the [How to Ask](https://stackoverflow.com/help/how-to-ask) guidance and updating your question to conform. – esqew Nov 19 '20 at 15:41

1 Answers1

-1

So when you are inserting into DB, you should not use '' for table columns... Instead of this: $wstaw="INSERT INTO uczen ('Nazwisko','Imie','Srednia_ocen','id_klasy') VALUES ('$nazwisko','$imie','$srednia','$idklasy)"; Try this: $wstaw="INSERT INTO uczen (Nazwisko,Imie,Srednia_ocen,id_klasy) VALUES ('$nazwisko','$imie','$srednia','$idklasy')";

Emiljano
  • 15
  • 7