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.
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 trying to add records to the database using laravel. When I click on register, I am redirected to a nee page but I get an error saying page has expired due to inactivity. The record isn't inserted into the database.
The files are as follows:
register.blade.php
<form action="/registers" method="post">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="form-group has-feedback">
<input type="text" class="form-control" name="username" placeholder="Full name">
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="email" class="form-control" name="email" placeholder="Email">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="number" class="form-control" name="contact" placeholder="Contact Number">
<span class="glyphicon glyphicon-earphone form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" name="pass" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" name="secondpass" placeholder="Retype password">
<span class="glyphicon glyphicon-log-in form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> I agree to the terms
</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
</div>
<!-- /.col -->
</div>
routes.php
Route::get('/register', 'mainController#register');
Route::post('/registers','mainController#registration');
mainController.php
public function register(){
return view('register');
}
public function registration(Request $request){
$username = $request->input('username');
$email = $request->input('email');
$contact = $request->input('contact');
$password = $request->input('secondpass');
$data=array("username"=>$username,"email"=>$email,"contact"=>$contact,"password"=>$password);
DB::table('users')->insert($data);
return Redirect::back();
}
Add CSRF token to the form:
{{ csrf_field }}
In Laravel 5.6+:
#csrf
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>
That is the error how do I fix it? Thats all of the code and I am confused with PHP. The template I have auto makes the error logs so I saw this and I can't access profile.php. Please help!
<?php
require_once('./pieces/header.php');
?>
<div class="row">
<div class="col-sm-8" id="center">
<div class="panel panel-default">
<div class="panel-heading">Profile Editor</div>
<div class="panel-body">
<form method="POST">
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-github-alt"></i></span>
<input type="text" class="form-control" value="<?php $user>getUsername(); ?>" title="Account username." disabled />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" class="form-control" value="<?php $user>getEmail(); ?>" title="Account email." disabled />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-trophy"></i></span>
<input type="text" class="form-control" value="<?php $user>getMembership(); ?>" title="Account membership." disabled />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-key"></i></span>
<input type="password" name="oldpassword" class="form-control" placeholder="Current Password" title="Current account password." value="" maxlength="32" autocomplete="off" />
</div>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-key"></i></span>
<input type="password" name="password" class="form-control" placeholder="New Password" value="" title="New account password." maxlength="32" autocomplete="off" />
</div>
<div class="form-group no-margn">
<input type="submit" name="save" class="btn btn-success btn-block" value="Save Changes"/>
</div>
</form>
</div>
</div>
</div>
Your sintaxe is wrong.
Your:
<?php $user>getUsername(); ?>
Correct:
<?php $user->getUsername(); ?>
In Drupal 9, getUsername is depreciated. Reference here.
It is recommended to use getAccountName or getDisplayName instead.
The error 'undefined function' is self explanatory, it means the function you are trying to call does not exist. Your post has the function "getusername()" while your code snippet has the function "getUsername()". Please not the uppercase "U" in the snippet and remember that php is a case sensitive language.
Thanks