I am trying this way but it doesnt work:
$sql = "INSERT INTO customers (userName,password,email,tel,companyName,idNumber,streetAddress,zipCode,city,coAdress) VALUES ($_POST['userName'],$_POST['password'],$_POST['email'] ,$_POST['tel'],$_POST['companyName'],$_POST['idNumber'],$_POST['streetAddress'],$_POST['zipCode'],$_POST['city'],$_POST['coAdress']);
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
I have now finally been able to see the output of:
Form.php
<form class="form" method="post" id="compReg" action="process.php">
<input type="submit">
connect.php
<?php
print_r($_POST);?>
The output when fields are exported is this:
Array ( [name] => Hedda Calhoun [email] => pinecozy@gmail.com [tel] => +539-48-6021045 [password] => Pa$$w0rd! [cpassword] => Pa$$w0rd! [companyName] => Underwood and Christian LLC [personalNumber] => 119 [streetAdress] => Enim officia et at numquam est voluptas placeat nulla et corporis dolorem in eum modi ratione incidunt nihil [zipCode] => 58366 [city] => Unde quis vel quam eiusmod rerum quaerat voluptatum labore provident [coAdress] => Nostrud culpa sint quis ab est in obcaecati illo consequat Ducimus nulla )
How can I load these into a php array so I can acces the and export them to the database?
You can access using Key
$_POST['name']
$_POST['email']
$_POST['tel']
For inserting records in database
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO USERS (name, email, tel)
VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['tel']."')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
By default $_POST is an associative array of variables passed through the post method. So you can access the values of this array itself as
$_POST['your_input_fieldname']
However if you want to bind a new array you can fire a foreach loop on $_POST as
$newarr = array();
foreach($_POST as $key=>$val)
{
$newarr[$key] = $val;
}
print_r($newarr);