Od razu zacznę od kodu:
<?php class showClass { public $mysqli; public $err = ''; public function __construct() { $this->mysqli = new mysqli("", "", "", ""); if ($this->mysqli->connect_errno) { $this->err = "Blad polaczenia: " . $this->mysqli->connect_error; } } public function show() { $select = "SELECT * FROM test_info"; $result = $this->mysqli->query($select); while ($newArray = $result->fetch_array()) { $resultArray[] = $newArray; } return $resultArray; } public function insert($fields) { $insert = "INSERT INTO test_info ('name', 'email') values ($fields)"; $this->mysqli->query($insert); } } $records = new showClass(); $i=0; foreach($records->show() as $key => $value) { $i++; } ?> <form action="index.php" method="POST"> <input type="text" id="name" name="name"><br> <input type="text" id="email" name="email"><br> <button type="submit" name="submit">Add record</button> </form> <?php } else { $name = $_POST['name']; $email = $_POST['email']; $fields = "'" . $name . "', '" . $email . "'"; $records->insert($fields); }
Działa mi to, ale nie do końca...
Niby wysyła, ale do bazy nie dodaje danych. var_dump() mi pokazuje iż zapytanie w metodzie jest poprawne, ale już samo query() jakby się nie wywołuje.
Ucze się PHP OOP i nie mam pomysłu na to teraz.
Prosze o jakiś feedback

Pozdrawiam!