I am having trouble integrating the "send OTP" function in my registration form. I was given an API from an SMS provider, but I do not know how to integrate it into my form. I need the user data to be recorded in my database after the verify the OTP. But how the verify process work? and how does the system would generate 6 digits random code to the user? I have been trying a different method and search online but none of that is working. Can anyone help?
Here is my form:
<div class="modal-body">
<form action="includes/signup.inc.php" method="POST" class="p-3">
<div class="form-group">
<label for="recipient-name" class="col-form-label">First Name</label>
<input type="text" class="form-control" placeholder="First Name" name="first" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" name="last" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Username</label>
<input type="text" class="form-control" placeholder="Username" name="uid" required="" >
</div>
<div class="form-group">
<label for="recipient-name1" class="col-form-label">Date of Birth</label>
<input type="date" class="form-control" placeholder="dob" name="dob" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Email Address</label>
<input type="email" class="form-control" placeholder="Email" name="email" required="" >
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Password</label>
<input type="password" class="form-control" placeholder="Password" name="pass" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Confirm Password</label>
<input type="password" class="form-control" placeholder="Confirm Password" name="c_pass" required="">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Are You Previously an Existing Member?</label>
<select class="form-control" id="recipient-name10" name="member">
<option>Yes</option>
<option>No</option>
</select>
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Where do you know about this membership?</label>
<select class="form-control" id="recipient-name11" name="outlet">
<option>The Metallic Kitchen # Golden Triangle Pelangi, JB</option>
<option>The Metallic Kitchen # Taman Mount Austin, JB</option>
<option>The Metallic Kitchen & Bar # Setapak Village, KL</option>
<option>None of the above</option>
</select>
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">OTP</label>
<input type="text" class="form-control" placeholder="OTP" name="otp" required="">
</div>
<div class="right-w3l mt-4 mb-3">
<input type="submit" class="form-control" value="Create account" name="submit">
</div>
</form>
</div>
and here is my sms provider API:
<?php
function sendSmsToEsms() {
$url = 'https://api.esms.com.my/sms/send';
// replace yourusername, yourpassword, and 60123456789 to suits your need
$data = array('user' => 'yourusername',
'pass' => 'yourpassword',
'to' => '60123456789',
'msg' => 'RM0.00 Hello from ESMS');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded; charset=utf-8",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
}
?>
here is my code for adding data into database:
<?php
if (isset($_POST['submit'])){
include_once 'db.php';
$first = mysqli_real_escape_string($conn,$_POST['first']);
$last = mysqli_real_escape_string($conn,$_POST['last']);
$uid = mysqli_real_escape_string($conn,$_POST['uid']);
$dob = mysqli_real_escape_string($conn,$_POST['dob']);
$email = mysqli_real_escape_string($conn,$_POST['email']);
$mobile = mysqli_real_escape_string($conn, $_POST['m_number']);
$pwd = mysqli_real_escape_string($conn,$_POST['pass']);
$member =mysqli_real_escape_string($conn, $_POST['member']);
$outlet = mysqli_real_escape_string($conn,$_POST['outlet']);
//ERROR HANDLERS
//CHECK FOR EMPTY FIELDS
//if(empty($first)||empty($last)||empty($uid)||empty($dob)||empty($email)||empty($mobile)||empty($pwd)||empty($member)||empty($outlet))
//{
//header("Location:../index.php?signup=empty");
//exit();
//}else{
//check if input characters are valid
//if(!preg_match("/^[a-zA-Z]*$/", $first)|| !preg_match("/^[a-zA-Z]*$/", $last)){
//header("Location:../signup.php?signup=invalid");
//exit();
//}else{
//check email
if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
echo "<script>alert('Invalid Email,please register again.')</script>";
echo "<script>window.open('../index.php','_self')</script>";
exit();
}else{
//check if username is same
$sql = "SELECT * FROM users WHERE user_uid = '$uid'";
$result = mysqli_query ($conn,$sql);
$resultCheck = mysqli_num_rows ($result);
if ($resultCheck > 0) {
echo "<script>alert('Username has been taken, please register again.')</script>";
echo "<script>window.open('../index.php','_self')</script>";
exit();
}else{
//Hashing pwd
$hashedPwd = password_hash($pwd,PASSWORD_DEFAULT);
//INSERT THE USER INTO THE DATABASE
$sql = "INSERT INTO users (user_first,user_last,user_uid,user_dob,user_email,user_mobile,user_pwd,user_member,user_outlet) VALUES ('$first','$last','$uid','$dob','$email','$mobile','$hashedPwd','$member','$outlet');";
mysqli_query($conn,$sql);
echo "<script>alert('You have been Registered Successfully, Please login from our main page')</script>";
echo "<script>window.open('../index.php','_self')</script>";
exit();
}
}
}
else{
header("Location:../index.php");
exit();
}
?>
You should temporarily save user data into database as well as the generated OTP and also an extra column to indicate if user is validated. (I suggest to hash OTP before saving).
Later when the user tries the username and OTP for login, you should check entered data against the database. If user and OTP are correct, check that column to validate the registration. If OTP is incorrect you can leave that column for more tries (or delete user account or void the OTP or regenerate a new OTP bases on your opinion).
to generate a random number use mt_rand algorythm:
$password=mt_rand (10,100);
and use it in API as follow:
'pass' => $password,
Related
My login table has Username and Password fields. I want to display the user's full name rather than their username when they logĀ in with their username and password. Instead of saying Welcome USERNAME on the next page, I want to say Welcome FULLNAME.
Here is the index.php or the login page in html:
<form action="" method="POST">
<div class="rows grid">
<div class="row">
<label for="username">User Name</label>
<input type="text" id="username" name="userName" placeholder="Enter Username" required>
</div>
<!--Password-->
<div class="row">
<label for="password">Password</label>
<input type="password" id="password" name="passWord" placeholder="Enter Password" required>
</div>
<!--Submit Button-->
<div class="row">
<input type="submit" id="submitBtn" name="submit" value="Login" required>
<!--Register Link-->
<span class="registerLink">Don't have an account? Register</span>
</div>
</div>
</form>
</div>
</div>
Here is the php:
<?php
// Submit
if(isset($_POST['submit'])){
// Store the names, password, email, number
$userName = $_POST['userName'];
$passWord = $_POST['passWord'];
// Selecting from database
$sql = "SELECT * FROM admin WHERE
usernames = '$userName' AND
passwords = '$passWord'";
// Exceute the query
$result = mysqli_query($conn, $sql);
// Count the number of the account of the same username and password
$count = mysqli_num_rows($result);
// Counts the results into arrys
$row = mysqli_fetch_assoc($result);
// Check if theres account in database
if ($count == 1){
$_SESSION['loginMessage'] = '<span class = "success">Welcome '.$userName.'</span>';
header('location:' .SITEURL. 'dashboard.php');
exit();
}
else{
$_SESSION['noAdmin'] = '<span class = "fail">Please check your username and password and try again.</span>';
header('location:' .SITEURL. 'index.php');
exit();
}
}
?>
Here is the register.php or register link:
<form action="" method="POST">
<div class="rows grid">
<!--Full Name-->
<div class="row">
<label for="fullname">Full Name</label>
<input type="text" id="fullname" name="fullName" placeholder="Enter Full Name" required>
</div>
<!--Username-->
<div class="row">
<label for="username">User Name</label>
<input type="text" id="username" name="userName" placeholder="Enter Username" required>
</div>
<!--Email-->
<div class="row">
<label for="email">Email</label>
<input type="email" id="email" name="emaiL" placeholder="Enter Email" required>
</div>
<!--Mobile Number-->
<div class="row">
<label for="number">Mobile Number</label>
<input type="number" id="number" name="numbeR" placeholder="Enter Mobile Number" required>
</div>
<!--Password-->
<div class="row">
<label for="password">Password</label>
<input type="password" id="password" name="passWord" placeholder="Enter Password" required>
</div>
<!--Submit Button-->
<div class="row">
<input type="submit" id="submitBtn" name="submit" value="Register" required>
<!--Try ko aban aban uni idelete-->
<span class="registerLink">Have an account already? Login</span>
</div>
</div>
</form>
Note: I want to display the input fullname in the welcome dashboard.
Please change your select query to parameterized prepared statement to avoid SQL injection attacks
To display the "fullname", just fetch the db record say into an associative array say $row and use $row["fullname"] (or $row["fullName"] if the field name is actually fullName)
Hence, change the block:
/// other code
$sql = "SELECT * FROM admin WHERE
usernames = '$userName' AND
passwords = '$passWord'";
// Exceute the query
$result = mysqli_query($conn, $sql);
// Count the number of the account of the same username and password
$count = mysqli_num_rows($result);
// Counts the results into arrys
$row = mysqli_fetch_assoc($result);
// Check if theres account in database
if ($count == 1){
$_SESSION['loginMessage'] = '<span class = "success">Welcome '.$userName.'</span>';
header('location:' .SITEURL. 'dashboard.php');
exit();
}
/// other code
to
<?php
/// other code
$sql = "SELECT * FROM admin WHERE usernames = ? AND passwords = ?";
$query = $conn->prepare($sql);
$query->bind_param("ss", $userName,$passWord );
$query->execute();
$result = $query->get_result();
$num = $result->num_rows;
if ($num == 1){
$row = $result->fetch_assoc();
$_SESSION['loginMessage'] = '<span class = "success">Welcome '.$row["fullname"].'</span>';
header('location:' .SITEURL. 'dashboard.php');
exit();
}
/// other code
?>
I have a form, with two options buyer and seller.
If the user is a buyer then the email id should enter and if the user is a seller then the mobile number should enter.
checkAccount_type(); // onload
$('input[name="account_type"]').click(function() {
checkAccount_type();
});
function checkAccount_type() {
if ($('#acc_seller').is(':checked')) {
$('.show_mobilefield').show();
$('.show_emailfield').hide();
} else {
$('.show_emailfield').show();
$('.show_mobilefield').hide();
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet">
<main class="site-main">
<div class="entry-content signup">
<div class="">
<form action="controller/access_control" name="signup_form" method="post" autocomplete="off">
<div class="signup_inner">
<div class="form-group d-flex">
<div class="">
<label class="container">
<input type="radio" name="account_type" value="1" id="acc_seller" checked="checked">
<span class="checkmark"></span> I am a Seller
</label>
</div>
<div class="">
<label class="container">
<input type="radio" name="account_type" value="2" id="acc_buyer">
<span class="checkmark"></span> I am a buyer
</label>
</div>
</div>
<div class="form-group show_mobilefield">
<label>Mobile no</label>
<input type="text" name="mobileno" class="form-control" placeholder="enter mobile no">
</div>
<div class="form-group show_emailfield">
<label>Email Address</label>
<input type="email" name="email" class="form-control" placeholder="enter email id">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="enter password here">
</div>
<div class="form-group">
<label>Confirm Password</label>
<input type="password" name="confirmpassword" class="form-control" placeholder="enter password here">
</div>
<div class="form-group mt-2">
<input type="submit" name="signup" class="" value="Signup">
<input type="hidden" name="action" value="singup">
</div>
</div>
</form>
</div>
</div>
</main>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
I am using below logic:
$account_type=sanitize_data($_POST['account_type']);
$password=$_POST['password'];
$confirmpassword=$_POST['confirmpassword'];
if (empty($account_type)) {
$errorMsg[]= "Please select account type";
}
elseif(empty($password)){
$errorMsg[] = 'Please enter password';
}
elseif($password!==$confirmpassword){
$errorMsg[] = 'Password didnot matched with confirm password';
}
else{
try {
if ($account_type==1) {
$mobileno=sanitize_data($_POST['mobileno']);
}
else{
$email=$_POST['email'];
}
$newpassword=password_hash($password, PASSWORD_BCRYPT,['cost' => 12]);
$data=array(
'email' => $email,
'mobileno'=>$mobileno,
'password' => $newpassword,
'account_type' => $account_type,
);
$sql="INSERT INTO `tbl_register`(`email`, `mobileno`, `password`, `account_type`) VALUES (:email,:mobileno, :password, :account_type)";
$stmt= $pdo->prepare($sql);
$stmt->execute($data);
//$response['error'] = "true";
header("Location:list.php");
} catch (Exception $e) {
$dbh->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
}
function sanitize_data($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = strip_tags($data);
$data = htmlspecialchars($data);
return $data;
}
I have an issue with the else part (try and insert query). I mean, If I enter the mobile number then I am getting the issue an email and if I enter email id then I am getting the issue on mobile.
I know I added the POST value email and mobile in the array and in the insert query.
Errors
Notice: Undefined variable: email in
Notice: Undefined variable: mobileno in
Do I need to use some if condition?
If email or mobile any one required at a time, then you can modify code as below :
$data=array(
'email' => $email ?? null,
'mobileno'=>$mobileno ?? null,
'password' => $newpassword,
'account_type' => $account_type,
);
I am aware there are a lot of questions on this regarding this issue, but I have looked through them all and none of the solutions seem to fix the issue for me. I have a form that when submitted, posts the data and it is retrieved via if(isset), as far as I know, all the syntax is correct, and the name attributes of the inputs are correct.
When I submit the form, the data in the form gets inserted into a mysql database, which works, the only issue is the blank page. Here is the php code at the top of the page and the relative html code.
PHP
<?php
require('connection.php');
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$body = $_POST['message'];
try {
$stmt = $db->prepare("INSERT INTO `contact` (`c_name`, `c_email`, `c_number`, `c_body`) VALUES (:name, :email, :num, :body)");
$stmt->execute(array(':name' => $name, ':email' => $email, ':num' => $number, ':body' => $body));
return $stmt;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
?>
HTML
<form method="post">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" name="name" class="form-control" id="name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="number">Contact Number:</label>
<input type="text" name="number" class="form-control" id="number">
</div>
<div class="form-group">
<label for="message">Message:</label>
<textarea name="message" class="form-control" id="message" rows="6"></textarea>
</div>
<input type="submit" name="submit" class="btn btn-primary" />
</form>
Sorry if what I'm going to ask is a dumb question, but I have read through and even apply some of the solutions to my problem but it's still not working. I've got the solutions from here:
1. Not Getting response after registration is successful
2. php register form not updating database
3. Inserted data was not saved during registration
I have a system where the user can register himself/herself as a candidate for job interviews. But right now, the system doesn't save their registration. I have go through the queries but find nothing. Perhaps anybody can point out where I have been doing wrong that make my system doesn't want to keep the data.
my register-candidates.php
<section class="content-header">
<div class="container">
<div class="row latest-job margin-top-50 margin-bottom-20 bg-white">
<h1 class="text-center margin-bottom-20">CREATE YOUR PROFILE</h1>
<form method="post" id="registerCandidates" action="adduser.php" enctype="multipart/form-data">
<div class="col-md-6 latest-job ">
<div class="form-group">
<input class="form-control input-lg" type="text" id="fname" name="fname" placeholder="First Name *" required>
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="lname" name="lname" placeholder="Last Name *" required>
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="email" name="email" placeholder="Email *" required>
</div>
<div class="form-group">
<textarea class="form-control input-lg" rows="4" id="aboutme" name="aboutme" placeholder="Brief intro about yourself *" required></textarea>
</div>
<div class="form-group">
<label>Date Of Birth</label>
<input class="form-control input-lg" type="date" id="dob" min="1960-01-01" max="1999-01-31" name="dob" placeholder="Date Of Birth">
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="age" name="age" placeholder="Age" readonly>
</div>
<div class="form-group">
<label>Passing Year</label>
<input class="form-control input-lg" type="date" id="passingyear" name="passingyear" placeholder="Passing Year">
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="qualification" name="qualification" placeholder="Highest Qualification">
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="stream" name="stream" placeholder="Stream">
</div>
<div class="form-group checkbox">
<label><input type="checkbox"> I accept terms & conditions</label>
</div>
<div class="form-group">
<button class="btn btn-flat btn-success">Register</button>
</div>
<?php
//If User already registered with this email then show error message.
if(isset($_SESSION['registerError'])) {
?>
<div class="form-group">
<label style="color: red;">Email Already Exists! Choose A Different Email!</label>
</div>
<?php
unset($_SESSION['registerError']); }
?>
<?php if(isset($_SESSION['uploadError'])) { ?>
<div class="form-group">
<label style="color: red;"><?php echo $_SESSION['uploadError']; ?></label>
</div>
<?php unset($_SESSION['uploadError']); } ?>
</div>
<div class="col-md-6 latest-job ">
<div class="form-group">
<input class="form-control input-lg" type="password" id="password" name="password" placeholder="Password *" required>
</div>
<div class="form-group">
<input class="form-control input-lg" type="password" id="cpassword" name="cpassword" placeholder="Confirm Password *" required>
</div>
<div id="passwordError" class="btn btn-flat btn-danger hide-me" >
Password Mismatch!!
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="contactno" name="contactno" minlength="10" maxlength="10" onkeypress="return validatePhone(event);" placeholder="Phone Number">
</div>
<div class="form-group">
<textarea class="form-control input-lg" rows="4" id="address" name="address" placeholder="Address"></textarea>
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="city" name="city" placeholder="City">
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="state" name="state" placeholder="State">
</div>
<div class="form-group">
<textarea class="form-control input-lg" rows="4" id="skills" name="skills" placeholder="Enter Skills"></textarea>
</div>
<div class="form-group">
<input class="form-control input-lg" type="text" id="designation" name="designation" placeholder="Designation">
</div>
<div class="form-group">
<label style="color: red;">File Format PDF Only!</label>
<input type="file" name="resume" class="btn btn-flat btn-danger" required>
</div>
</div>
</form>
</div>
</div>
</section>
adduser.php
<?php
//To Handle Session Variables on This Page
session_start();
//Including Database Connection From db.php file to avoid rewriting in all files
require_once("db.php");
//If user clicked register button
if(isset($_POST)) {
//Escape Special Characters In String First
$firstname = mysqli_real_escape_string($conn, $_POST['fname']);
$lastname = mysqli_real_escape_string($conn, $_POST['lname']);
$address = mysqli_real_escape_string($conn, $_POST['address']);
$city = mysqli_real_escape_string($conn, $_POST ['city']);
$state = mysqli_real_escape_string($conn, $_POST ['state']);
$contactno = mysqli_real_escape_string($conn, $_POST ['contactno']);
$qualification = mysqli_real_escape_string($conn, $_POST ['qualification']);
$stream = mysqli_real_escape_string ($conn, $_POST['stream']);
$passingyear = mysqli_real_escape_string($conn, $_POST['passingyear']);
$dob = mysqli_real_escape_string($conn, $_POST['dob']);
$age = mysqli_real_escape_string($conn, $_POST['age']);
$designation = mysqli_real_escape_string($conn, $_POST['designation']);
$aboutme = mysqli_real_escape_string($conn, $_POST['aboutme']);
$skills = mysqli_real_escape_string($conn, $_POST['skills']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
//Encrypt Password
$password = base64_encode(strrev(md5($password)));
//sql query to check if email already exists or not
$sql = "SELECT email FROM users WHERE email='$email'";
$result = $conn->query($sql);
//if email not found then we can insert new data
if($result->num_rows == 0) {
//This variable is used to catch errors doing upload process. False means there is some error and we need to notify that user.
$uploadOk = true;
//Folder where you want to save your image. THIS FOLDER MUST BE CREATED BEFORE TRYING
$folder_dir = "uploads/resume/";
//Getting Basename of file. So if your file location is Documents/New Folder/myResume.pdf then base name will return myResume.pdf
$base = basename($_FILES['resume']['name']);
//This will get us extension of your file. So myimage.pdf will return pdf. If it was image.doc then this will return doc.
$imageFileType = pathinfo($base, PATHINFO_EXTENSION);
//Setting a random non repeatable file name. Uniqid will create a unique name based on current timestamp. We are using this because no two files can be of same name as it will overwrite.
$file = uniqid() . "." . $resumeFileType;
//This is where your files will be saved so in this case it will be uploads/image/newfilename
$filename = $folder_dir .$file;
//We check if file is saved to our temp location or not.
if(file_exists($_FILES['resume']['tmp_name'])) {
//Next we need to check if file type is of our allowed extention or not. I have only allowed pdf. You can allow doc, jpg etc.
if($resumeFileType == "pdf") {
//Next we need to check file size with our limit size. I have set the limit size to 5MB. Note if you set higher than 2MB then you must change your php.ini configuration and change upload_max_filesize and restart your server
if($_FILES['resume']['size'] < 500000) { // File size is less than 5MB
//If all above condition are met then copy file from server temp location to uploads folder.
move_uploaded_file($_FILES["resume"]["tmp_name"], $filename);
} else {
//Size Error
$_SESSION['uploadError'] = "Wrong Size. Max Size Allowed : 5MB";
$uploadOk = false;
}
} else {
//Format Error
$_SESSION['uploadError'] = "Wrong Size. Max Size Allowed : 5MB ";
$uploadOk = false;
}
} else {
//File not copied to temp location error.
$_SESSION['uploadError'] = "Something Went Wrong. File Not Uploaded. Try Again.";
$uploadOk = false;
}
//If there is any error then redirect back.
if($uploadOk == false) {
header("Location: register-candidates.php");
exit();
}
//sql new registration insert query
$sql = "INSERT INTO users(firstname, lastname, email, password, address, city, state, contactno, qualification, stream, passingyear, dob, age, designation, resume, hash, aboutme, skills) VALUES ('$firstname', '$lastname', '$email', '$password', '$address', '$city', '$state', '$contactno', '$qualification', '$stream', '$passingyear', '$dob', '$age', '$designation', '$file', '$hash', '$aboutme', '$skills')";
if($conn->query($sql)===TRUE) {
//If data inserted successfully then Set some session variables for easy reference and redirect to company login
$_SESSION['registerCompleted'] = true;
header("Location: login-candidates.php");
exit();
} else {
//If data failed to insert then show that error. Note: This condition should not come unless we as a developer make mistake or someone tries to hack their way in and mess up :D
echo "Error " . $sql . "<br>" . $conn->error;
}
} else {
//if email found in database then show email already exists error.
$_SESSION['registerError'] = true;
header("Location: register-candidates.php");
exit();
}
//Close database connection. Not compulsory but good practice.
$conn->close();
} else {
//redirect them back to register page if they didn't click register button
header("Location: register-candidates.php");
exit();
}
thank you for the help and your time.
I think you should to debug your app by following those steps :
Try to direct insert data from SQL command in your ManagementInterface
Try to echo $var | var_dump($var) of each input you get from your form when you reach your register.php.
Try to see if you reach your condition like if(isset($_POST["var"]&&!empty($_POST["var"])) but if you can echo them it's not here you have to search
It might be your queries statement that block you.
You should try to improve your code with prepared statement for your SQL queries, it will be more readable and maintenable. Also, i think that mysqli & co are deprecated.
I hope it will be usefull for you and it ill help you to find your error.
Respond in comment if this doesn't help you, 'ill try to find out why
Regards
You have not defined $resumeFileType and in order for your script to execute, it has to check that the $resumeFileType is a PDF.
I am seeking some more advice on the way to handle this.
I have got one page with links to each admin member which when clicked takes their display name over. On the second page which is a form it takes that display names and populates the subject field with their display name. I need to grab the email address that is associated to that user too but use that as the email address the form on the second page gets sent to as currently my script can only send it to an email address I hard code into it.
So page one is:
<?php
$args1 = array(
'role' => 'committee',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$committee = get_users($args1);
foreach ($committee as $user) {
echo '
<a href="../contact-form?displayname=' . $user->display_name . '"><b style="font-size:18px;">
<tr>
<td style="padding: 10px;">' .$user->job_title .' - </td>
<td style="padding: 10px;">' .$user->display_name .'</td>
</tr></b></a><br><br>';
}
?>
Page two is:
<?php $displayname = $_GET['displayname'];?>
<form role="form" method="post" action="../mailuser.php">
<div class="form-group">
<input type="hidden" name="displayname" value="<?php echo $displayname ?>">
<input type="text" name="hp" class="hp" value="" alt="if you fill this field out then your email will not be sent">
</div>
<div class="form-group">
<label for="InputName">Your name</label>
<input type="name" class="form-control" id="InputName" placeholder="Enter your name" name="username">
</div>
<div class="form-group">
<label for="InputEmail">Email address</label>
<input type="email" class="form-control" id="InputEmail" placeholder="you#example.com" name="emailFrom">
</div>
<div class="form-group">
<label for="InputMsg">Message</label>
<textarea class="form-control" rows="8" id="InputMsg" placeholder="Please begin typing your message..." name="emailMessage"></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right">Send</button>
</form>
And my send script has my email hard coded in as:
$mail->From = 'myemail#dummy.com';
So I need that be variable depending on which person you clicked on in the first place. It needs to be sent to both my hard coded email and also the persons email that is associated to them in the Wordpress user database.
Based on our comment discussion, you should be able to do something along the lines of the following on page two. Be sure to correct my email_address, I'm not sure if that's how get_users returns the email address or not.
<?php
$displayname = $_GET['displayname'];
$args1 = array(
'role' => 'committee',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$committee = get_users($args1);
$matchingEmail = false;
foreach ($committee as $user) {
if ( !$matchingEmail && $user->display_name == $displayname ) {
// great, we found our match
$matchingEmail = $user->email_address; // I don't know if email_address is right, double check this and modify if necessary
}
}
if ( $matchingEmail ) {
// only proceed if a matching email address is found
?>
<form role="form" method="post" action="../mailuser.php">
<div class="form-group">
<input type="hidden" name="displayname" value="<?php echo $displayname; ?>">
<input type="hidden" name="matchingEmail" value="<?php echo $matchingEmail; ?>">
<input type="text" name="hp" class="hp" value="" alt="if you fill this field out then your email will not be sent">
</div>
<div class="form-group">
<label for="InputName">Your name</label>
<input type="name" class="form-control" id="InputName" placeholder="Enter your name" name="username">
</div>
<div class="form-group">
<label for="InputEmail">Email address</label>
<input type="email" class="form-control" id="InputEmail" placeholder="you#example.com" name="emailFrom">
</div>
<div class="form-group">
<label for="InputMsg">Message</label>
<textarea class="form-control" rows="8" id="InputMsg" placeholder="Please begin typing your message..." name="emailMessage"></textarea>
</div>
<button type="submit" class="btn btn-primary pull-right">Send</button>
</form>
<?php
} else {
?>
<p>Something is wrong, I can't find your email address! Please try again.</p>
<?php
}
?>
Finally on page three, where you send the email, you can do something like:
<?php $mail->addAddress(stripslashes( $_POST["matchingEmail"] ) ); ?>