Hello Experts,
I hate PHP when these things comes in front of me every time when i create and insert query I stuck up by viewing everything is ok but not working don't know why. please help me out
previewuser.php
<?php
include_once('includes/header.php');
include_once('includes/session.php');
include_once('includes/functions.php');
include_once('includes/connection.php');
if(isset($_POST["submit"])) {
echo add_user();
}
?>
<form method="POST" action="previewuser.php">
<label>
<p>First Name</p>
<p class="info"><?php echo $fname = $_SESSION["fname"]; ?></p>
<input type="hidden" name="fname" value="<?php echo $fname; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Last Name</p>
<p class="info"><?php echo $lname = $_SESSION["lname"]; ?></p>
<input type="hidden" name="lname" value="<?php echo $lname; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Father's Name</p>
<p class="info"><?php echo $father = $_SESSION["father"]; ?></p>
<input type="hidden" name="father" value="<?php echo $father; ?>" />
</label>
<div class="clear"></div>
<label>
<p>User Name</p>
<p class="info"><?php echo $uname = $_SESSION["username"]; ?></p>
<input type="hidden" name="uname" value="<?php echo $uname; ?>" />
</label>
<div class="clear"></div>
<label>
<p>User Type</p>
<p class="info"><?php echo $utype = $_SESSION["utype"]; ?></p>
<input type="hidden" name="utype" value="<?php echo $utype; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Date Of Birth</p>
<p class="info"><?php echo $dob = $_SESSION["dob"]; ?></p>
<input type="hidden" name="dob" value="<?php echo $dob; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Address</p>
<p class="info"><?php echo $add = $_SESSION["add"]; ?></p>
<input type="hidden" name="add" value="<?php echo $add; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Phone Number</p>
<p class="info"><?php echo $phno = $_SESSION["phnumber"]; ?></p>
<input type="hidden" name="phno" value="<?php echo $phno; ?>" />
</label>
<div class="clear"></div>
<label>
<p>E-Mail</p>
<p class="info"><?php echo $email = $_SESSION["email"]; ?></p>
<input type="hidden" name="email" value="<?php echo $email; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Designation</p>
<p class="info"><?php echo $desig = $_SESSION["designation"]; ?></p>
<input type="hidden" name="desig" value="<?php echo $desig; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Employment Status</p>
<p class="info"><?php echo $emp = $_SESSION["empstatus"]; ?></p>
<input type="hidden" name="desig" value="<?php echo $emp; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Allowed Clock In</p>
<p class="info"><?php echo $aci = $_SESSION["aci"]; ?></p>
<input type="hidden" name="empstatus" value="<?php echo $aci; ?>" />
</label>
<div class="clear"></div>
<label>
<p>Shift</p>
<p class="info"><?php echo $shft = $_SESSION["shft"]; ?></p>
<input type="hidden" name="shift" value="<?php echo $shft; ?>" />
</label>
<div class="clear"></div>
<div class="input" style="text-align:center;">
<p> </p>
<input type="submit" value="Preview" class="btn1" name="submit" />
<a href="adduser.php" style="text-decoration:none;" class="btn1">Edit<a/>
</div>
</form>
Insert function
function add_user() {
global $connection;
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$fathername = $_POST['father'];
$uname = $_POST['uname'];
$pswrd = $_POST['pswrd'];
$utype = $_POST['utype'];
$dob = $_POST['dob'];
$add = $_POST['add'];
$phno = $_POST['phno'];
$email = $_POST['email'];
$desig = $_POST['desig'];
$emp = $_POST['emp'];
$aci = $_POST['aci'];
$shift = $_POST['shift'];
$insert = "INSERT INTO users (fname, lname, father_name, utype, dob, address, ph_number, email, designation, emp_stat, clock_in, shift, user_name, password)";
$insert .= "VALUES ('$fname', '$lname', '$fathername', '$utype', '$dob', '$add', '$phno', '$email', '$desig', '$emp', '$aci', '$shift', '$uname', '$pswrd')";
$insert_query = mysqli_query($connection, $insert);
if(confirm_query($insert_query)) {
$_SESSION["message"] = "Your user was added successfully";
redirect_to("mng_user.php");
} else {
$_SESSION["message"] = "There were some errors please re-add the user";
redirect_to("adduser.php");
}
}
and please do let me know also how do i cal $connection in global scope as a parameter
Thank You