Reputation: 11
I am making a prototype website for a recruitment agency and I am having a problem with uploading any data to the database which has been created for this prototype system. This is the register a new user page and it will not send any of the information in the html text fields to the database.
This is my code this far -
<?php
require (__DIR__.'/connections/connections.php');
if(isset($_POST['Register'])){
session_start();
$Title = $_POST['Consultant_Title'];
$Fname = $_POST['Consultant_First_Name'];
$Lname = $_POST['Consultant_Last_Name'];
$Cbranch = $_POST['Consultant_Branch'];
$Email = $_POST['Email'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$StorePassword = password_hash($Password, PASSWORD_BCRYPT, array('cost' => 10));
$spl = $con->query("INSERT INTO consultant_details (Title, Fname, Lname, Cbranch )Values('{$Title}', '{$Fname}', '{$Lname}', '{$Cbranch}')");
$spl = $con->query("INSERT INTO users ( Email, Username, Password )Values('{$Title}', '{$Email}', '{$Username}', '{$StorePassword}')");
header('location: Login.php');
}
?>
Html -
<h2>Staff Register </h2>
<div class="clr"></div>
<form action="" method="post" name="Registerform" id="Registerform">
<div class="FormElement"><select style="font-size: medium;">
<option name="Consultant_Title" id="Consultant_Title" value="Mr">Mr</option>
<option name="Consultant_Title" id="Consultant_Title" value="Mrs">Mrs</option>
<option name="Consultant_Title" id="Consultant_Title" value="Miss">Miss</option>
<option name="Consultant_Title" id="Consultant_Title" value="Ms">Ms</option>
<option name="Consultant_Title" id="Consultant_Title" value="Dr">Dr</option>
<option name="Consultant_Title" id="Consultant_Title" value="Professor">Professor</option>
</select></div>
<div class="FormElement">
<input name="Consultant_First_Name" type="text" required="required" class="TField" id="Consultant_First_Name" placeholder="First Name"> <input name="Consultant_Last_Name" type="text" required="required" class="TField" id="Consultant_Last_Name" placeholder="Last Name">
</div>
<div class="FormElement">
<input name="Username" type="text" required="required" class="TField" id="Username" placeholder="Username"> <input name="Password" type="text" pattern=".{6,}" required title="6 characters minimum" class="TField" id="Password" placeholder="Password">
</div>
<div class="FormElement">
<input name="Consultant_Branch" type="text" required="required" class="TField" id="Consultant_Branch" placeholder="Consultant Branch"> <input name="Email" type="text" required="required" class="TField" id="Email" placeholder="Email">
</div>
<div class="FormElement"><input name="Register" type="submit" class="button" id="Register" value="Register"></div>
</form>
Upvotes: 0
Views: 62
Reputation: 74219
As mentioned in comments, <select>
holds the name attribute, not <option>
. The value(s) will then populate from the one(s) given for value="x"
.
Then you have 3 columns and 4 values in your second query (missing column for "title") and attempting to perform a multi-query.
Consult these following links
and apply that to your code.
Another thing, since you're using password_hash()
, use a prepared statement with that.
You are open to SQL injection. Consult the following on Stack:
Your connection is also unknown, whether it is MySQL_, or MySQLi_ or PDO.
Different APIs do not intermix, so use the same MySQL API from connection to query, call it an insight.
To check if a query truly was successful, use affected_rows()
:
PHP has a set of functions specifically for handling password hashes.
If you're using a PHP version less than 5.5 you can use the password_hash()
compatibility pack.
Read this tutorial to see how you can put these things into action.
Upvotes: 4
Reputation: 723
After each query try to handle any mysql error regarding your queries.
Example.
$spl = $con->query("INSERT INTO users ( Email, Username, Password )
Values ('{$Title}', '{$Email}', '{$Username}', '{$StorePassword}')"
or die(mysqli_error($con)));
This will guide you in dealing with your mysql errors.
Upvotes: 0
Reputation: 5532
first put name attribute in select tag
<div class="FormElement"><select name="Consultant_Title" style="font-size: medium;">
<option id="Consultant_Title" value="Mr">Mr</option>
<option id="Consultant_Title" value="Mrs">Mrs</option>
<option id="Consultant_Title" value="Miss">Miss</option>
<option id="Consultant_Title" value="Ms">Ms</option>
<option id="Consultant_Title" value="Dr">Dr</option>
<option id="Consultant_Title" value="Professor">Professor</option>
</select></div>
second missed mentioning title in your query and you gave it in values
$spl = $con->query("INSERT INTO users ( Title, Email, Username, Password ) Values('{$Title}', '{$Email}', '{$Username}', '{$StorePassword}')");
Upvotes: 0