now the problem I am having is that the data submitted from the form is not being inserted into the database. My code is inserting a record into the users table, but only the static value "active" is being inserted. Nothing from the form fields is being included, and is blank.
connection.php is the initial database connection file, which is working as its inserting a row albeit blank (with exception of the acc_active set to active hardcoded). Search.php is not important
Here is my code.
<?php
require "connection.php";
require "search.php";
$var_username = mysqli_real_escape_string($conn, $_POST['username']);
$var_password = mysqli_real_escape_string($conn, $_POST['password']);
$var_email = mysqli_real_escape_string($conn, $_POST['email']);
if (isset($_GET['reg'])){
if ($_GET['reg']=='1'){
$verify = mysqli_query("SELECT COUNT(*) AS NUM FROM users WHERE username = '$var_username'");
$result = mysqli_fetch_array($verify);
if($result[0]==1){
$error_msg = "Username exists";
}else{
$query = "INSERT INTO users(username, password, email, acc_active)VALUES('$var_username','$var_password','$var_email','active')";
if (mysqli_query($conn, $query)){
echo "success";
}else{
echo "failed". $sql ."<br>". mysqli_error($conn);
}
}
}
}
mysqli_close($conn);
?>
And here is the html form, this is inside a
<form method="post" action="/rail/register.php?reg=1" style="text-align:center">
<input type="text" placeholder="Username..." name="username" />
<input type="text" placeholder="Email..." name="email" />
<input type="password" placeholder="Password..." name="password" />
<input type="password" placeholder="Confirm Password..." name="password-confirm" />
<a href="/rail/login">Return / Cancel</a>
<input type="submit" name="Register" value="Register" />
</form>
So I am reloading the page with value reg=1 to indicate an insert, I am verifying that there are no other records with that username, I am then running insert query
Any help would be much appreciated. Thanks in advance. Ive left the above code very basic at this stage, Ill do error messages, and verification that password/confirm password fields match etc. as well as hashing once basic setup is complete.