Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z kodem.
chmuraa
post 27.10.2017, 19:46:42
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 27.10.2017

Ostrzeżenie: (0%)
-----


Witajcie forumowicze! Zaczynam dopiero z programowaniem. Robię teraz listę todo. Posiadam pewien problem, nie dodaje mi rekordów w kodzie.
CODE
<?php
require 'header.php';
?>
<html>
<body>
<div class="center">
<form action="connect.php" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Tytul</label>
<input type="email" class="form-control is-invalid .hidden-xs" id="exampleInputTitle" aria-describedby="titleHelp" placeholder="Enter title" name="nazwa">
<small id="emailHelp" class="form-text text-muted .hidden-xs">Wpisz tytul zadania</small>
<div class="invalid-feedback">
Podaj tytul zadania.
</div>
</div>

<div class="form-group1">
<label for="exampleFormControlTextarea1">Opis</label>
<textarea class="form-control is-invalid .hidden-xs" id="exampleFormControlTextarea1" rows="3" name="opis"></textarea>
</div>
<div class="invalid-feedback">
Podaj opis.
</div>

<input type="date" name="data" />
<div class="form-group">
<label for="sel1">Priorytet</label>
<select class="form-control .hidden-xs" id="sel1" name="priorytet">
<option></option>
<option>Low</option>
<option>Medium</option>
<option>High</option>
</select>
</div>
<a href="submit.php" class="btn btn-info .hidden-xs" role="button">Add Task</a>
</div>
</div>
</form>
</body>
<?php
require 'footer.php';
?>


oraz tu dam łączenie do bazy danych
CODE


<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "tasks";
$nazwa = $_POST['nazwa'];
$opis = $_POST['opis'];
$priorytet = $_POST['priorytet']

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO tasks (nazwa, opis, priorytetl)
VALUES ('$nazwa', '$opis', '$priorytet')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>



Proszę o szybką pomoc.

Edit:

Używam mampa.

Ten post edytował chmuraa 27.10.2017, 19:50:16
Go to the top of the page
+Quote Post
ohm
post 27.10.2017, 20:16:41
Post #2





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

Ostrzeżenie: (0%)
-----


A gdzie/jak zapisujesz dane do bazy?

Ten post edytował ohm 27.10.2017, 20:17:55
Go to the top of the page
+Quote Post
chmuraa
post 27.10.2017, 20:18:28
Post #3





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 27.10.2017

Ostrzeżenie: (0%)
-----


CODE
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "tasks";

tutaj
Go to the top of the page
+Quote Post
ohm
post 27.10.2017, 22:03:54
Post #4





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

Ostrzeżenie: (0%)
-----


To są tylko dane do bazy, a gdzie wykonujesz samo zapytanie typu INSERT?
Go to the top of the page
+Quote Post
viking
post 28.10.2017, 05:33:47
Post #5





Grupa: Zarejestrowani
Postów: 6 378
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Sprawdź co zawiera tablica POST. poczytaj o prepare i sql injection.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 21.06.2025 - 05:49