NEW CODE FROM YOUR SUGGESTIONS (STILL NOT WORKING) I am trying to get values from an registration form to a php page with the post method and then echo it in that page so I know it works. If it does I will try to get all the values and insert them into my user table. I dont mind the sql injection risks and that I have to clean the input for now I just want to make it work. But it doesnt, do you guys see what I do wrong? Also is it possible to instead get all the values in an array and post them so I dont have to use so many variables.
form.php (another page)
<?php include_once("connect.php"); ?>
<?php include_once("getTrycksaker.php"); ?>
<?php include_once("header.php"); ?>
<!-- BUILD COLUMN SYSTEM FOR CROSSDEVICE USABILITY -->
<div class="container">
<div class="row">
<div class="col-md-1 col-sm-0 col-xs-0"></div>
<div class="col-md-10 col-sm-12 col-xs-12">
<h3 class="title"> Registrering Företagskonto</h3><hr>
<div class="alert alert-info" role="alert">Ange vänligen inloggningsuppgifter samt namn och telefonnummer till företagets kontaktperson.</div>
</div>
<div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
<div class="col-md-1 col-sm-0 col-xs-0"></div>
<form class="form" method="post" id="compReg">
<div class="col-md-5 col-sm-12 col-xs-12">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" name="name" id="name" class="form-control" placeholder="Kontaktperson"></div><br>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<input type="email" name="email" id="email" class="form-control" placeholder="E-postadress"></div><br>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></span>
<input type="text" class="form-control" placeholder="Telefon"></div><br>
</div>
<div class="col-md-5 col-sm-12 col-xs-12">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" name="password" id="password" class="form-control" placeholder="Lösenord"></div><br>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" name="cpassword" id="cpassword" class="form-control" placeholder="Upprepa Lösenordet"></div><br>
</div>
<div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
<div class="col-md-1 col-sm-0 col-xs-0"></div>
<div class="col-md-10 col-sm-12 col-xs-12">
<br><div class="alert alert-info" role="alert">Ange vänligen företagets namn, postadress samt organisationsnummer. Avvikande leveransadresser kan registreras vid order.</div>
</div>
<div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
<div class="col-md-1 col-sm-0 col-xs-0"></div>
<div class="col-md-5 col-sm-12 col-xs-12">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
<input type="text" class="form-control" placeholder="Företagsnamn"></div><br>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
<input type="text" class="form-control" placeholder="Organisationsnummer"></div><br>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
<input type="text" class="form-control" placeholder="Gatuadress"></div><br>
</div>
<div class="col-md-5 col-sm-12 col-xs-12">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
<input type="text" class="form-control" placeholder="Postnummer"></div><br>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
<input type="text" class="form-control" placeholder="Postort"></div><br>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-paperclip"></span></span>
<input type="text" class="form-control" placeholder="Eventuell c/o adress"></div><br>
</div>
<div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<div class="row">
<div class="col-md-1 col-sm-0 col-xs-0"></div>
<div class="col-md-10 col-sm-0 col-xs-0">
<label class="btn btn-info btn-file">Skapa Konto <input id="submitBtn" onclick="rAlert('Go')" type="submit" style="display: none;"><span class="glyphicon glyphicon-ok-sign" ></span></label>
<br><br><br>
</div>
</form>
<div class="col-md-1 col-sm-0 col-xs-0"></div>
</div>
<?php include_once("footer.php"); ?>
process.php (another page)
<?php print_r($_POST);?>
You can get the values using element name.All the values are inside $_POST
Array.Just print_r($_POST)
.You will see all the posted values.
In process.php
;
extract($_POST);
echo $name;//prints name
echo $email;//prints email
The
extract()
function imports variables into the local symbol table from an array.This function uses array keys as variable names and values as variable values. For each element it will create a variable in the current symbol table.
You can use <?php print_r($_POST); ?>
to check exactly what is being passed to php. This will show all variables passed from the form and their values.
Also worth noting that only inputs with valid name attributes will be passed by the form.
I think, this example code will help you. run my code and use this idea in your code.
in form.php
<form class="form" method="post" action="process.php">
<input type="text" name="name[]" value="a"/>
<input type="text" name="name[]" value="b"/>
<input type="text" name="name[]" value="c"/>
<label>Skapa Konto <input type="submit" ></label>
in process.php
<?php
$nvals = count($_REQUEST['name']);
// do something with $_REQUEST['name'][$i] for example
echo 'Hello ' . $_REQUEST['name'][1] . '!';
?>
it will print that 'Hello b!'
if you want to get all values using for loop use this code.
<?php
$nofval = count($_REQUEST['name']);
for ($i = 0; $i < $nofval; $i++) {
echo 'Hello ' .$_REQUEST['name'][$i] . '!';
}
?>