I am trying to add a form in my html which will get 12 input box and save it to mysql. but its echoing failed as because of submit button perhaps. because in if for the isset submit button the else is forwarding message. Code for my html
<body class="templatemo-bg-image-2">
<div class="container">
<div class="col-md-12">
<form class="form-horizontal templatemo-contact-form-1" role="form" action="input.php" method="post">
<div class="form-group">
<div class="col-md-12">
<h1 class="margin-bottom-15">Marketing Samurai 2017</h1>
<h2 class="margin-bottom-15">Registration form</h2>
<p>This contact form is provided by templatemo that can be used for your websites. Credit goes to <a rel="nofollow" href="http://unsplash.com">Unsplash</a> for the background image.</p>
</div>
<hr>
<h4 class="margin-bottom-15">Team Info</h4>
<hr>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">University Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-university"></i>
<input name="uname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Team</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-users"></i>
<input name="tname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Trix Id</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-money"></i>
<input name="tcode" type="text" class="form-control" id="name" placeholder="Bkash transection Code">
</div>
</div>
</div>
<h4 class="margin-bottom-15">Leader Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="lname" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="lmail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="lcont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<h4 class="margin-bottom-15">1st Member Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="m1name" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="m1mail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="m1cont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<h4 class="margin-bottom-15">2nd Member Info</h4>
<hr>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-user"></i>
<input name="m2name" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Email</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-envelope-o"></i>
<input name="m2mail" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Contact</label>
<div class="templatemo-input-icon-container">
<i class="fa fa-phone"></i>
<input name="m2cont" type="text" class="form-control" id="name" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<button type="submit" value="Submit" name="submit" class="btn btn-success pull-right">></button>
</div>
</div>
</form>
</div>
</div>
Code for php
<?php
$con = mysqli_connect('localhost','root','');
if(!$con){
echo 'Not Connected To Server';
}
if (!mysqli_select_db ($con,'test')) {
echo 'Database Not Selected';
}
if (isset($_POST['submit'])){
$uni = $_POST['uname'];
$team = $_POST['tname'];
$trix = $_POST['tcode'];
$leader = $_POST['lname'];
$lemail = $_POST['lmail'];
$leadercon = $_POST['lcont'];
$mname = $_POST['m1name'];
$memail = $_POST['m1mail'];
$mcon = $_POST['m1cont'];
$mname3 = $_POST['m2name'];
$memail3 = $_POST['m2mail'];
$mcon3 = $_POST['m2cont'];
$sql = "INSERT INTO 'memberdetails' (uninam, team, trixid, mem, mail, cont, mem1, mail1, con1, mem2, mail2, con2) VALUES ('$uni', '$team', '$trix', '$leader', '$lemail', '$leadercon', '$mname', '$memail', '$mcon', '$mname3', '$memail3', '$mcon3' )";
if (!mysqli_query($con,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted Successfully';
}
header("refresh:2; url=index.html");
} else {
echo "failed";
}
I haven't made any validation yet. and I am trying with msqli and database, table is connecting then why the error is coming? I just made the submit button just to insert docs. whats should I do to prevent the fail message. Thanks in advance. :)
Submit must be <input> with name or it won't be available using $_POST['submit']
<input type="submit" value="Submit" name="submit" />
Try to remove "submit" text from name of form button and replace with another text
<button type="submit" value="Submit" name="form_sumit" class="btn btn-success pull-right">></button>
Related
I have a register/log in page with POST method. this is the form.php:
<form method="POST" action="process.php">
<div class="section">
<div class="container">
<div class="row full-height justify-content-center">
<div class="col-12 text-center align-self-center py-5">
<div class="section pb-5 pt-5 pt-sm-2 text-center">
<h6 class="mb-0 pb-3"><span>Log In </span><span>Sign Up</span></h6>
<input class="checkbox" type="checkbox" id="reg-log" name="reg-log"/>
<label for="reg-log"></label>
<div class="card-3d-wrap mx-auto">
<div class="card-3d-wrapper">
<div class="card-front">
<div class="center-wrap">
<div class="section text-center">
<h4 class="mb-4 pb-3">Log In</h4>
<div class="form-group">
<input type="text" name="username" class="form-style" placeholder="username" id="Username" autocomplete="off">
<i class="input-icon uil uil-at"></i>
</div>
<div class="form-group mt-2">
<input type="password" name="password4" class="form-style" placeholder="password" id="password4" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<button name="login" id="login" class="btn mt-4">Log in</button>
<p class="mb-0 mt-4 text-center">Forgot your password?</p>
</div>
</div>
</div>
<div class="card-back">
<div class="center-wrap">
<div class="section text-center" style="padding-top: 2.5rem;">
<h4 class="mb-2 pb-3">Sign Up</h4>
<div class="form-group">
<input type="text" name="username" class="form-style" placeholder="Username" id="username" autocomplete="off">
<i class="input-icon uil uil-user"></i>
</div>
<div class="form-group mt-2" style="padding-top: 2.5rem;">
<input type="email" name="email" class="form-style" placeholder="Email" id="email" autocomplete="off">
<i class="input-icon uil uil-at"></i>
</div>
<div class="form-group mt-2" style="padding-top: 2.5rem;">
<input type="password" name="password" class="form-style" placeholder="Password" id="password" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<div class="form-group mt-2" style="padding-top: 2.5rem;">
<input type="password" name="password2" class="form-style" placeholder="Repeat Password" id="password2" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<button name="register" id="register" class="btn mt-4">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
In my process.php i have:
if(isset($_POST['register'])){
...do the register
}
and it works just fine.
I coded the login and it did not worked. I figured out that $username = $_POST['username'] and $password= $_POST['password'] are just empty. So i tried this just to see if they take any values:
if(isset($_POST['login'])){
echo $_POST['username']
}
and it is just blank.
A quick fix, change the IDs in your login section inputs from this:
<input type="text" id="username">
<input type="password" id="password4">
To this:
<input type="text" id="loginUsername">
<input type="password" id="loginPassword">
You can then check them in your process.php file by doing the following:
if (isset($_POST['login'])) {
echo 'Username: ' .$_POST['loginUsername']. ' Password: '. $_POST['loginPassword'];
}
As another commenter has mentioned, having two separate forms would also solve the problem.
I have a webpage in php which has some form data in sql the user can update the data.
The form is like below:
<?php
$id=$_GET['id'];
$SelSql = "SELECT * FROM `registers` WHERE id=$id";
$res = mysqli_query($link, $SelSql);
$r = mysqli_fetch_assoc($res);
?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
<div class="breadcrumbs">
<div class="breadcrumbs-inner">
<div class="row m-0">
<div class="col-sm-4">
<div class="page-header float-left">
<div class="page-title">
<h1>Member Details</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="content">
<div class="animated fadeIn">
<div class="row">
<div class="col-xs-6 col-sm-6">
<div class="card">
<div class="card-body card-block">
<div class="form-group">
<label class=" form-control-label">Member ID</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>
<input class="form-control" value="<?php echo $r['id']; ?>" readonly>
</div>
</div>
<form method="post">
<div class="form-group">
<label class=" form-control-label">First Name</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-address-card-o"></i></div>
<input name="fname" class="form-control" value="<?php echo $r['firstname']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Last Name</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-address-card-o"></i></div>
<input name="lname" class="form-control" value="<?php echo $r['lastname']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Mobile Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-mobile"></i></div>
<input name="mobile" class="form-control" value="<?php echo $r['mobilenumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Company</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building"></i></div>
<input name="company" class="form-control" value="<?php echo $r['company']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Designation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-clipboard"></i></div>
<input name="designation" class="form-control" value="<?php echo $r['designation']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Experience</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-sort-numeric-asc"></i></div>
<input name="experience" class="form-control" value="<?php echo $r['experience']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Address</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-marker"></i></div>
<input name="address" class="form-control" value="<?php echo $r['address']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Address Line 2</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-marker"></i></div>
<input name="addressline2" class="form-control" value="<?php echo $r['addressline2']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">City</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building-o"></i></div>
<input name="city" class="form-control" value="<?php echo $r['city']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">State</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map"></i></div>
<input name="state" class="form-control" value="<?php echo $r['state']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Pin</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-map-pin"></i></div>
<input name="pin" class="form-control" value="<?php echo $r['pin']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Country</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-globe"></i></div>
<input name="country" class="form-control" value="<?php echo $r['country']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Whatsapp Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-phone-square"></i></div>
<input name="whatsapp" class="form-control" value="<?php echo $r['Whatsapp']; ?>">
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6">
<div class="card">
<div class="card-body card-block">
<div class="form-group">
<label class=" form-control-label">Alternate Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-phone"></i></div>
<input name="alternate" class="form-control" value="<?php echo $r['alternatenumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Email</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-envelope"></i></div>
<input name="email" class="form-control" value="<?php echo $r['Email']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Company Registration Number</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-registered"></i></div>
<input name="crn" class="form-control" value="<?php echo $r['CompanyRegNumber']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Date of Incorporation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-calendar"></i></div>
<input name="doi" class="form-control" value="<?php echo $r['Date_Incorporation_orBusi_Stp']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">GST IN</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-sort-numeric-asc"></i></div>
<input name="gstin" class="form-control" value="<?php echo $r['GSTIN']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Services Offered</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-question-circle"></i></div>
<input name="services" class="form-control" value="<?php echo $r['Services_Offered']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Annual Turnover</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-money"></i></div>
<input name="annualt" class="form-control" value="<?php echo $r['Annual_Turnover']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Fee</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-money"></i></div>
<input name="fee" class="form-control" value="<?php echo $r['Fee']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Mode of Payment</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-credit-card"></i></div>
<input name="mop" class="form-control" value="<?php echo $r['Mode_of_Payment']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Recommended By (A)</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<input name="reca" class="form-control" value="<?php echo $r['Recommended_by_A']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Recommended By (B)</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<input name="recb" class="form-control" value="<?php echo $r['Recommended_by_B']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Terms and Conditions</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="tac" class="form-control" value="<?php echo $r['termsandconditions']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Declaration</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="dec" class="form-control" value="<?php echo $r['Declaration']; ?>">
</div>
</div>
<div class="form-group">
<label class=" form-control-label">Confirmation</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-check"></i></div>
<input name="cof" class="form-control" value="<?php echo $r['confirmation']; ?>">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Update">
</form>
</div>
</div>
</div>
<?php
if(isset($_POST) & !empty($_POST)){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['mobile'];
$company = $_POST['company'];
$designation = $_POST['designation'];
$experience = $_POST['experience'];
$address = $_POST['address'];
$addressline2 = $_POST['addressline2'];
$city = $_POST['city'];
$state = $_POST['state'];
$pin = $_POST['pin'];
$country = $_POST['country'];
$whatsapp = $_POST['whatsapp'];
$alternate = $_POST['alternate'];
$email = $_POST['email'];
$crn = $_POST['crn'];
$doi = $_POST['doi'];
$gstin = $_POST['gstin'];
$services = $_POST['services'];
$annualt = $_POST['annualt'];
$fee = $_POST['fee'];
$mop = $_POST['mop'];
$reca = $_POST['reca'];
$recb = $_POST['recb'];
$tac = $_POST['tac'];
$dec = $_POST['dec'];
$cof = $_POST['cof'];
}
$UpdateSql = "UPDATE `registers` SET firstname='$fname', lastname='$lname', mobilenumber='$email', experience='$experience',
designation='$designation', company='$company', address='$address', addressline2='$addressline2',
city='$city', state='$state', pin='$pin', country='$country',
Whatsapp='$whatsapp', alternatenumber='$alternate', Email='$email', CompanyRegNumber='$crn',
Date_Incorporation_orBusi_Stp='$doi', GSTIN='$gstin', Services_Offered='$services', Annual_Turnover='$annualt',
Declaration='$dec', Fee='$fee', confirmation='$cof', Mode_of_Payment='$mop',
Recommended_by_A='$reca', Recommended_by_B='$recb', termsandconditions='$tac' WHERE id=$id";
$res = mysqli_query($link, $UpdateSql);
if($res){
header('location: update.php');
}else{
$fmsg = "Failed to update data.";
}
?>
the update feature is working completely fine, when the user loads this page, the data is displayed in the form which is editable by user,now the problem is when the user updates the data, the page reloads and updates the data in database but, the page is displayed with empty values in the input fields, such that if the user clicks the update button again by mistake, the database field becomes blank. what is the problem in my code, what should i do to stop this mistake?
The issue is fundamentally how you are passing parameters. If you are POSTing then the parameter id will not be accessible with your current code, which expects id to be a GET parameter. Try this:
$id=$_POST['id'];
Or better yet,
$id=$_REQUEST['id'];
The $_REQUEST variable is an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. Since it seems that you need the id parameter for both GET and POST methods, $_REQUEST should be used here.
UPDATE
Your mysqli_query($link, $UpdateSql) function should be wrapped in the if(isset($_POST) & !empty($_POST)) condition. It looks like it is executing on each load the way the code currently is.
if(isset($_POST) & !empty($_POST)){
...
$UpdateSql = "....."
$res = mysqli_query($link, $UpdateSql);
}
Pass id, when you are redirecting page, on success as following
if($res){
header('location: update.php?id='.$id);
exit;
}else{
$fmsg = "Failed to update data.";
}
I am a beginner in web development, I used have an html elements, like textbox and other type of elements, I want to use them as my object and when they have a value and click a button, it will save the value of all the elements in mysql.
I have a code like this, but it cannot be inserted and anything does not happen when clicking a button.
Please help.
PHP:
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'ytp');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(!$db ) {
die('Could not connect: ' . mysqli_error());
}
$fname = "";
$mname = "";
$lname = "";
$funame = "";
$cnum = "";
$bday = "";
$age = "";
$add = "";
if (isset($_POST['submit'])){
$fname = $_POST['fName'];
$mname = $_POST['mName'];
$lname = $_POST['lName'];
$funame = $_POST['fuName'];
$cnum = $_POST['Cnumber'];
$bday = $_POST['bday'];
$age = $_POST['age'];
$add = $_POST["address"];
}
$sql = "INSERT INTO employee ".
"(fName,mName,lName,fuName,cNumber,bDay,Age,Address) ".
"VALUES ('$fname','$mname','$lname','$funame','$cnum','$bday','$age','$add' )";
if (! mysqli_query($db , $sql)){
echo 'Cannot Insert';
}
else{
echo 'Success';
}
?>
HTML:
<div class="content">
<div class="row">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h5 class="title">Add User Information</h5>
</div>
<div class="card-body">
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</form>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</div>
</div>
</div>
</div>
Your HTML form is closing before submit button. You should close that after submit button and also need to manage hierarchy of opening form tag as below:
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="card-body">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</form>
Hope it helps you.
the form has been closed before the submit button.
the </form> tag should be placed after the <div class="card-footer">...</div>.
please try it. hope it will help.
At the moment I have this bootstrap login form which when you click Sign Up it switches to the sign up form. I've implemented the code for signing up in php along side some validation in PHP using $_POST to check to see if the fields are filled in and passwords match etc however, each time I submit the sign up for it switches back to the login form on the same page however, I want to it to remain on the sign up form if any of the validations fail. How would I go about doing this as simply changing the action="" in the form doesn't work. Here's the code for the bootrstrap login and sign up.
<div class="container">
<div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-info" >
<div class="panel-heading">
<div class="panel-title">Sign In</div>
<div style="float:right; font-size: 80%; position: relative; top:-10px">Forgot password?</div>
</div>
<div style="padding-top:30px" class="panel-body" >
<div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
<form action="login.php" method="post" id="loginform" class="form-horizontal" role="form">
<h5 style="margin-top: 0px"><b>To place an order, please sign in.</b></h5>
<div id="error"></div>
<br>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="username or email">
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input id="login-password" type="password" class="form-control" name="password" placeholder="password">
</div>
<div class="input-group">
<div class="checkbox">
<label>
<input id="login-remember" type="checkbox" name="remember" value="1"> Remember me
</label>
</div>
</div>
<div style="margin-top:10px" class="form-group">
<!-- Button -->
<div class="col-sm-12 controls">
<p><input id="btn-login" class="btn btn-success" type="submit" name="submit" value="Login" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</div>
</div>
<div class="form-group">
<div class="col-md-12 control">
<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
Don't have an account!
<a href="#" onClick="$('#loginbox').hide(); $('#signupbox').show()">
Sign Up Here
</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div id="signupbox" style="display:none; margin-top:50px" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Sign Up</div>
<div style="float:right; font-size: 85%; position: relative; top:-10px"><a id="signinlink" href="#" onclick="$('#signupbox').hide(); $('#loginbox').show()">Sign In</a></div>
</div>
<div class="panel-body" >
<form action="" method="post" id="signupform" class="form-horizontal" role="form">
<div id="errorRegistration"></div>
<div id="signupalert" style="display:none" class="alert alert-danger">
<p>Error:</p>
<span></span>
</div>
<div class="form-group">
<label for="username" class="col-md-3 control-label">Username</label>
<div class="col-md-9">
<input type="text" class="form-control" name="newusername" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-3 control-label">Email</label>
<div class="col-md-9">
<input type="text" class="form-control" name="newemail" placeholder="Email Address">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-3 control-label">Password</label>
<div class="col-md-9">
<input type="password" class="form-control" name="newpassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="confirm-password" class="col-md-3 control-label">Confirm Password</label>
<div class="col-md-9">
<input type="password" class="form-control" name="newconfirm-password" placeholder="Confirm Password">
</div>
</div>
<div class="form-group">
<label for="forename" class="col-md-3 control-label">Forename</label>
<div class="col-md-9">
<input type="text" class="form-control" name="forename" placeholder="Forename">
</div>
</div>
<div class="form-group">
<label for="surname" class="col-md-3 control-label">Surname</label>
<div class="col-md-9">
<input type="text" class="form-control" name="surname" placeholder="Surname">
<div class="form-group">
<!-- Button -->
<div class="col-md-offset-3 col-md-9">
<p><input id="btn-signup" class="btn btn-info" type="submit" name="submittedRegister" value="  Sign Up" /></p>
<input type="hidden" name="submittedRegister" value="TRUE" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
Thanks again for the help! :D
There are many ways to do this, but a simple one would be something like this:
<div id="signupbox" style="<? if (empty($_POST['submittedRegister'])) echo 'display: none;' ?> margin-top:50px" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
(And a modified version for #loginbox)
However, I don't recommend to use style attributes, if you can use classes. It might be easier, but classes help keeping the code clean and maintainable
I am wrapping functions in php pages in the functions.php and to access these pages, i put an action and a value in the url. I also have a function_calls.php which requests the action and its value and passes it to a switch case which calls the appropriate function. The problem i have is that i case i want to edit a field . I dont have an appropriate case(for the switch) which i want to look something like admin.php?action=edit?id=some_id.
function_calls.php
<?php
require_once "functions.php";
if (isset($_REQUEST['action'])) {
$option = $_REQUEST['action'];
echo $option;
switch ($option) {
case "complaints":
complaint();
break;
case "users":
users();
break;
case "officers":
officers();
break;
case "register_officer":
register_officer();
break;
case "register_student":
register_student();
break;
case "add_event":
add_event();
break;
default:
complaint();
break;
}
} else {
echo '<div class="jumbotron">
<h1>Welcome To The Administration Panel </h1>
<p>You can manage accounts and view the complaints here.</p>
</div>';
}
functions.php
<?php
include_once "include/db_connect.php";
function register_student()
{
?>
<section>
<div class="row">
<div class="col-md-7 col-md-offset-1">
<form class="" method="post" action="">
<div class="row">
<div class="col-md-6 ">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Firstname" name="firstname" required=""
class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Lastname" name="lasttname" required=""
class="form-control">
</div>
</div>
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" placeholder="Email" name="email" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Registration Number" name="reg_no" required=""
class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-phone"></i></span>
<input type="text" placeholder="Phone" name="phone" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Password" name="password" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Confirm Password" name="conf_password" required=""
class="form-control">
</div>
<div class="row">
<!--<div class="col-md-6 checkbox">
<label><input type="checkbox">Remember me</label>
</div>-->
<div class="col-md-12">
<button class="btn btn-success btn-block pull-right" type="submit" name="register">Register
Student
</button>
</div>
</div>
</form>
</div>
</div>
</section>
<?php
}
function register_officer()
{
?>
<section>
<div class="row">
<div class="col-md-7 col-md-offset-1">
<form class="" method="post" action="register.php">
<div class="row">
<div class="col-md-6 ">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Firstname" name="firstname" required=""
class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Lastname" name="lastname" required=""
class="form-control">
</div>
</div>
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" placeholder="Email" name="email" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="text" placeholder="Rank" name="rank" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-phone"></i></span>
<input type="text" placeholder="Phone" name="phone" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Password" name="password" required="" class="form-control">
</div>
<div class="input-group margin-bottom-20">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" placeholder="Confirm Password" name="conf_password" required=""
class="form-control">
</div>
<div class="row">
<!--<div class="col-md-6 checkbox">
<label><input type="checkbox">Remember me</label>
</div>-->
<div class="col-md-12">
<button class="btn btn-success btn-block pull-right" type="submit" name="register_officer">
Register Officer
</button>
</div>
</div>
</form>
</div>
</div>
</section>
<?php
}
This would be a bit more elegant solution than yours:
<?php
require_once 'functions.php';
if (isset($_GET['action'])) {
$option = $_GET['action'];
echo $option;
if(in_array($option, get_defined_functions()['user']) === true) {
call_user_func($option);
} else {
complaint();
}
} else {
echo '<div class="jumbotron">
<h1>Welcome To The Administration Panel </h1>
<p>You can manage accounts and view the complaints here.</p>
</div>';
}
So then you can define a function edit() which will be automatically called by the call_user_func without altering the switch each time you add a new function.