Māris Skrīvelis Posted February 24, 2018 Report Share Posted February 24, 2018 Sveiki. Man ir problēma sakarā ar formu, kas nesūta datus uz mysql tabulu. Būtu pateicīgs par risinājumiem. MySQL : , kur id ir primary un automātiski palielinās, bet user_group pēc default ir 'user'. Ar pieslēgšanos mysql tabulu viss ir kārtībā. Problēma ir kaut kur starp formu un php kodu. PHP : <?php session_start(); require 'html/test.html'; //connect to database $db = new mysqli("localhost", "root", "" ,"company" ); if (isset($_POST['register_form'])) { $name = $_POST['name']; $surename = $_POST['surename']; $email = $_POST['email']; $phone = $_POST['phone']; $city = $_POST['city']; $postcode = $_POST['postcode']; $region = $_POST['region']; $username = $_POST['username']; $password = $_POST['password']; $password_re = $_POST['password_re']; if ($password == $password_re) { //create new user // ievietot DB $sql = $db->prepare("INSERT INTO login(name, surename, email, phone, city, postcode, region, username, password) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"); $sql->bind_param("sssssssss", $name, $surename, $email, $phone, $city, $postcode, $region, $username, $password); $sql->execute(); // izsuacam funkciju, kas ievieto loetotāja datus DB $_SESSION['message'] = "You are now logged in!"; $_SESSION['username'] = $username; $sql->close(); header("location: index.php");//redirect to home page } } ?> HTML : <form id="regForm" action="register.php" name="register_form"> <h1>Reģistrācija:</h1> <div class="col-xs-12"> <p class="title"> Pamatinformācija: </p> </div> <div class="col-md-6 col-xs-12"> <input placeholder="Vārds..." name="name" type="text" required> </div> <div class="col-md-6 col-xs-12"> <input placeholder="Uzvārds..." name="surename" type="text" required> </div> <div class="col-xs-12"> <p class="title"> Kontaktinformācija: </p> </div> <div class="col-md-6 col-xs-12"> <input placeholder="E-pasts..." name="email" type="email" required> </div> <div class="col-md-6 col-xs-12"> <input placeholder="Tālruņa nr..." name="phone" type="phone" required> </div> <div class="col-xs-12"> <p class="title"> Dzīvesvieta: </p> </div> <div class="col-xs-12"> <input placeholder="Pilsēta" name="city" type="text" required> </div> <div class="col-md-6 col-xs-12"> <input placeholder="Pasta indekss" name="postcode" type="text" required> </div> <div class="col-md-6 col-xs-12"> <input placeholder="Rajons" name="region" type="text" required> </div> <div class="col-xs-12"> <p class="title"> Profila informācija: </p> </div> <div class="col-xs-12"> <input placeholder="Lietotājvārds..." name="username" type="text" required> </div> <div class="col-md-6 col-xs-12"> <input placeholder="Parole..." name="password" type="password" required> </div> <div class="col-md-6 col-xs-12"> <input placeholder="Atkārtota parole..." name="password_re" type="password" required> </div> <div class="col-xs-12"> <input class="btn btn-lg btn-success" type="submit" value="Reģistrēties"></input> </div> </form> Quote Link to comment Share on other sites More sharing options...
aaxc Posted February 24, 2018 Report Share Posted February 24, 2018 Kādu kļūdas paziņojumu tev izvada izpildot šo? Quote Link to comment Share on other sites More sharing options...
Val Posted February 24, 2018 Report Share Posted February 24, 2018 Formai trūkst method="post", kā arī register_form nebūs iekš $_POST masīva. Izvēlies ko citu vai pieliec register_form kā hidden field. Quote Link to comment Share on other sites More sharing options...
Māris Skrīvelis Posted February 25, 2018 Author Report Share Posted February 25, 2018 (edited) Hah kā es varēju nepamanīt, ka aizmirsu method pielikt... Paldies par vērīgumu, bet pieliekot post nekas nestrādā. Pabūros un kaut kā aizgāja, neatceros, kā vakardien to panācu strādāt. Pieņemu, ka pie vianas bija isset nomaiņa uz if (!empty($_POST)){} pogas pielabošana : <input class="btn btn-lg btn-success" type="submit" value="Reģistrēties" name="Submit"></input> un formas atribūtu piekoriģēšana : <form action="" name="register-form" method="post"> Paldies par atsaucību :) Edited February 26, 2018 by Māris Skrīvelis Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.