Bjørn Arild Andersen
New Member
Bruker MAMP, Brackets, PHP versjon: 7.2.10.
Det virker som om selve koblingen mot databasen fungerer, men jeg får ikke lov til å sende informasjon inn dit.
- failed to register user, er tilbakemeldingen.
Hva er det jeg ikke ser? Den fungerte først, så stoppet det å fungere etter noen endringer...
Databasekobling: connect.php
<?php
//Connection to MAMP_db on localhost.
$connection = mysqli_connect("localhost", "root", "root");
if(!$connection){
echo "Failed to connect to database!";
}
$dbselect = mysqli_select_db($connection, "aktiv_tid");
if(!$dbselect){
echo "Failed to select database!";
}
?>
script som kjøres for registrering:
<?php
require_once ('../cms/connect.php');
if(isset($_POST) & !empty($_POST)){
echo $user_company_name = $_POST['user_company_name'];
echo "<br />";
echo $user_firstname = $_POST['user_firstname'];
echo "<br />";
echo $user_lastname = $_POST['user_lastname'];
echo "<br />";
echo $user_email = $_POST['user_email'];
echo "<br />";
echo $user_phone = $_POST['user_phone'];
echo "<br />";
echo $user_address = $_POST['user_address'];
echo "<br />";
echo $user_postnr = $_POST['user_postnr'];
echo "<br />";
echo $user_username = $_POST['user_username'];
echo "<br />";
echo $user_password = $_POST['user_password'];
echo $sql = "INSERT INTO `registered_user` (user_company_name, user_firstname, user_lastname, user_email, user_phone, user_address, user_postnr, user_username, user_password) VALUES ('$user_company_name', $user_firstname, '$user_lastname', '$user_email', '$user_phone', '$user_address', '$user_postnr', '$user_username', '$user_password')";
$result = mysqli_query($connect, $sql);
if($result){
echo "User registration succefull!";
} else {
echo "Failed to register user!";
}
}
?>
HTML skjemaet som fylles ut:
<form method="post" action="?register">
<div class="form-group w-100">
<input type="text" name="user_company_name" class="form-control" id="company_name" placeholder="Firmanavn">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_firstname" class="form-control" id="firstname_user" placeholder="Fornavn">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_lastname" class="form-control" id="lastname_user" placeholder="Etternavn">
</div>
<div class="form-group w-50 float-left">
<input type="email" name="user_email" class="form-control" id="user_email" placeholder="E-post">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_phone" class="form-control" id="user_phone" placeholder="Telefon/Mobil">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_address" class="form-control" id="user_address" placeholder="Adresse">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_postnr" class="form-control" id="user_postnr" placeholder="Postnummer">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_username" class="form-control" id="user_username" placeholder="Brukernavn">
</div>
<div class="form-group w-50 float-left">
<input type="password" name="user_password" class="form-control" id="user_password" placeholder="Passord">
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Registrer</button>
</form>
Det virker som om selve koblingen mot databasen fungerer, men jeg får ikke lov til å sende informasjon inn dit.
- failed to register user, er tilbakemeldingen.
Hva er det jeg ikke ser? Den fungerte først, så stoppet det å fungere etter noen endringer...
Databasekobling: connect.php
<?php
//Connection to MAMP_db on localhost.
$connection = mysqli_connect("localhost", "root", "root");
if(!$connection){
echo "Failed to connect to database!";
}
$dbselect = mysqli_select_db($connection, "aktiv_tid");
if(!$dbselect){
echo "Failed to select database!";
}
?>
script som kjøres for registrering:
<?php
require_once ('../cms/connect.php');
if(isset($_POST) & !empty($_POST)){
echo $user_company_name = $_POST['user_company_name'];
echo "<br />";
echo $user_firstname = $_POST['user_firstname'];
echo "<br />";
echo $user_lastname = $_POST['user_lastname'];
echo "<br />";
echo $user_email = $_POST['user_email'];
echo "<br />";
echo $user_phone = $_POST['user_phone'];
echo "<br />";
echo $user_address = $_POST['user_address'];
echo "<br />";
echo $user_postnr = $_POST['user_postnr'];
echo "<br />";
echo $user_username = $_POST['user_username'];
echo "<br />";
echo $user_password = $_POST['user_password'];
echo $sql = "INSERT INTO `registered_user` (user_company_name, user_firstname, user_lastname, user_email, user_phone, user_address, user_postnr, user_username, user_password) VALUES ('$user_company_name', $user_firstname, '$user_lastname', '$user_email', '$user_phone', '$user_address', '$user_postnr', '$user_username', '$user_password')";
$result = mysqli_query($connect, $sql);
if($result){
echo "User registration succefull!";
} else {
echo "Failed to register user!";
}
}
?>
HTML skjemaet som fylles ut:
<form method="post" action="?register">
<div class="form-group w-100">
<input type="text" name="user_company_name" class="form-control" id="company_name" placeholder="Firmanavn">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_firstname" class="form-control" id="firstname_user" placeholder="Fornavn">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_lastname" class="form-control" id="lastname_user" placeholder="Etternavn">
</div>
<div class="form-group w-50 float-left">
<input type="email" name="user_email" class="form-control" id="user_email" placeholder="E-post">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_phone" class="form-control" id="user_phone" placeholder="Telefon/Mobil">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_address" class="form-control" id="user_address" placeholder="Adresse">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_postnr" class="form-control" id="user_postnr" placeholder="Postnummer">
</div>
<div class="form-group w-50 float-left">
<input type="text" name="user_username" class="form-control" id="user_username" placeholder="Brukernavn">
</div>
<div class="form-group w-50 float-left">
<input type="password" name="user_password" class="form-control" id="user_password" placeholder="Passord">
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Registrer</button>
</form>