I have a to get a data from this form and insert it into database.
I am not able to find any solution online.
Everything works on the browser but the data is not getting stored into the table and echo inside the if block is not printed on screen.
The code is what can be seen below.
HTML
<form action="" method="POST">
<div class="container-fluid">
<div class="container">
<div class="row">
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-10 col-lg-4 col-md-offset-3" style="top:100px">
<div class="offer offer-radius offer-primary">
<div class="shape">
<div class="shape-text">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<div class="offer-content">
<h4 style="margin-left:70px;font-size:20px">Enter your details below and enroll your slot</h4>
<div class="container col-xs-12">
<div class="stepwizard">
<div class="stepwizard-row setup-panel">
<div class="stepwizard-step">
<a href="#step-1" type="button" class="btn btn-primary btn-circle">
<i class="glyphicon glyphicon-user" style="margin-left: -18px;top: -24px;font-size: 90%;"></i></a>
</div>
<div class="stepwizard-step">
<a href="#step-2" type="button" class="btn btn-default btn-circle" disabled="disabled">
<i class="glyphicon glyphicon-education" style="margin-left: -18px;top: -24px;font-size: 90%;"></i></a>
</div>
<div class="stepwizard-step">
<a href="#step-4" type="button" class="btn btn-default btn-circle" disabled="disabled">
<i class="glyphicon glyphicon-ok" style="margin-left: -18px;top: -24px;font-size: 90%;"></i></a>
</div>
</div>
</div>
<div class="row setup-content" id="step-2">
<div class="col-xs-12">
<div class="col-md-10">
<h3>Qualification</h3>
<div class="col-xs-12 col-xs-offset-1" style="top:-50px">
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
</div>
<div class="col-xs-12" style="clear:both;top:-45px">
<input maxlength="20" type="text" required="required" class="form-control" placeholder="B Tech" readonly="" />
</div>
<div class="col-xs-12 form-group" style="clear:both;top:-40px">
<label for="subject">
Year of Pass out</label>
<input maxlength="20" type="text" required="required" class="form-control" placeholder="2016" readonly="" />
</div>
<div class="col-xs-12 form-group" style="clear:both;top:-40px">
<label for="subject">
Branch</label>
<select id="subject" name="subject" class="form-control" required="required">
<option value="na" selected="">Choose One:</option>
<option value="service">Computer Science</option>
<option value="suggestions">Information Technology</option>
<option value="product">Electronics & Communication</option>
<option value="product">Electronics & Electrical</option>
<option value="product">Instrumentation</option>
</select>
</div>
<div class="col-xs-12" style="clear:both;top:-40px">
<label for="subject">
Percentage (%)</label>
<input maxlength="6" type="text" class="form-control" placeholder="Your Percentage" name="percentage" />
</div>
</div>
</div>
</div>
</div>
<div class="row setup-content" id="step-1">
<div class="col-xs-12">
<div class="col-md-12">
<div class="container">
<div class="row">
<div class="col-xs-4">
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
<h3>Personal Information</h3>
<div class="col-xs-12" style="padding:15px">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<input maxlength="100" type="text" class="form-control" placeholder="First Name" name="F_Name" />
</div>
</div>
<div class="col-xs-12" style="clear:both;padding:10px">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<input maxlength="100" type="text" class="form-control" placeholder="Last Name" name="L_Name" />
</div>
</div>
<div class="col-xs-12" style="clear:both;padding:10px">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<input maxlength="100" type="text" class="form-control" placeholder="Your Email" name="EmailID" />
</div>
</div>
<div class="col-xs-12" style="clear:both;padding:10px">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
<input maxlength="14" type="text" class="form-control" placeholder="(+91) 555-555-5555" name="Phone_Number" />
</div>
</div>
<div class="col-xs-12" style="clear:both;padding:10px">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
<input maxlength="14" type="text" class="form-control" placeholder="Reference Code" name="R_Code" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row setup-content" id="step-4">
<div class="col-xs-12">
<div class="col-xs-12">
<div class="container" style="height:307px;">
<h4>Registered</h4>
<div class="col-xs-4" style="margin-left:-60px;top:60px">
<button class="btn btn-success completeBtn btn-lg pull-right" type="button" name="proceed">Proceed to payment</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
PHP
<?php
$cn= mysqli_connect('localhost','testuser','password','invoicedb');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "string";
if(isset($_POST["proceed"]))
{echo "string";
$fname=$_POST['F_Name'];
$lname=$_POST['L_Name'];
$emailID=$_POST['EmailID'];
$phone_number=$_POST['Phone_Number'];
$reference_code=$_POST[‘R_Code’];
$branch=$_POST[‘subject’];
$percentage=$_POST[‘percentage’];
echo "insert into students(first_name,last_name,email,phone_number,reference_code,branch,percentage) VALUES ('$fname','$lname','$emailID','$phone_number','$reference_code','$branch','$percentage')";
mysqli_query($cn,"insert into students(first_name,last_name,email,phone_number,reference_code,branch,percentage) VALUES ('$fname','$lname','$emailID','$phone_number','$reference_code','$branch','$percentage')");
//best outside the if statement so user isn't stuck on a white blank page.
header("location:confirm.php");
exit;
}
?>
You can access $_POST[] values only if your form is submitted,
So, Replace this,
<button class="btn btn-success completeBtn btn-lg pull-right" type="button" name="proceed">Proceed to payment</button>
with This,
<button class="btn btn-success completeBtn btn-lg pull-right" type="submit" name="proceed">Proceed to payment</button>
It will work, without replacing your button with input.
If you are submitting the form in the same page then you should use -
<?php
$cn= mysqli_connect('localhost','testuser','password','invoicedb');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "string";
if($_SERVER["REQUEST_METHOD"] == "POST")
{echo "string";
$fname=$_POST['F_Name'];
$lname=$_POST['L_Name'];
$emailID=$_POST['EmailID'];
$phone_number=$_POST['Phone_Number'];
$reference_code=$_POST[‘R_Code’];
$branch=$_POST[‘subject’];
$percentage=$_POST[‘percentage’];
echo "insert into students(first_name,last_name,email,phone_number,reference_code,branch,percentage) VALUES ('$fname','$lname','$emailID','$phone_number','$reference_code','$branch','$percentage')";
mysqli_query($cn,"insert into students(first_name,last_name,email,phone_number,reference_code,branch,percentage) VALUES ('$fname','$lname','$emailID','$phone_number','$reference_code','$branch','$percentage')");
//best outside the if statement so user isn't stuck on a white blank page.
header("location:confirm.php");
exit;
}
?>
if(isset($_POST["proceed"])){}
$_POST["proceed"] is not set at all, it needs a value in it to make sure it is set.
instead of checking if, just print the post values and try if your form is getting submitted.
inside php tag write below code and try echoing the data.
echo '<pre>';
print_r($_POST);
echo '----------------';
print_r($_REQUEST);
Related
hope all is well. I really really really do need help submitting a jQuery step wizard form. I did get a plugin to help but it does most of its functionalities in jQuery and not html.
At the moment i have:
- Created the database and necessary table
- Created html form using jquery steps
- Connected the form to the database
- Connected database to html table for display
This is my html code:
<div class="modal fade" id="pat_add_modal" tabindex="-1" role="dialog" aria-labelledby="add_patient_label">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="add_patient_label">Add New Patient</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<!-- PHP Form Processor -->
<?php
include 'db.php';
if(isset($_POST['submit'])){
$pat_sname = $_POST['pat_sname'];
$pat_fname = $_POST['pat_fname'];
$pat_gender = $_POST['pat_gender'];
$pat_dob = $_POST['pat_dob'];
$pat_phone = $_POST['pat_phone'];
$pat_email = $_POST['pat_email'];
$insurance_companies = $_POST['insurance_companies'];
$card_no = $_POST['card_no'];
$pat_allergies = $_POST['pat_allergies'];
$pat_history = $_POST['pat_history'];
$pat_address = $_POST['pat_address'];
$nok_name = $_POST['nok_name'];
$nok_phone = $_POST['nok_phone'];
$nok_email = $_POST['nok_email'];
$pat_dependants = $_POST['pat_dependants'];
$pat_work = $_POST['pat_work'];
$pat_work_address = $_POST['pat_work_address'];
$work_phone = $_POST['work_phone'];
$work_email = $_POST['work_email'];
$ins_sql = "INSERT INTO patients (surname, first_name, gender, dateofbirth, phone, email, insurance_co, insurance_card_no, allergies, medical_history, full_address, nok_name, nok_phone, nok_email, dependants, palce_of_work, work_full_address, work_phone, work_email) VALUES ('$pat_sname', '$pat_fname', '$pat_gender', '$pat_dob', '$pat_phone', '$pat_email', '$insurance_companies', '$card_no', '$pat_allergies', '$pat_history', '$pat_address', '$nok_name', '$nok_phone', '$nok_email', '$pat_dependants', '$pat_work', '$pat_work_address', '$work_phone', '$work_email')";
$run_sql = mysqli_query($conn, $ins_sql);
echo "insertion success";
}else{
echo "insertion failed";
}
?>
<div class="card-block wizard-content">
<form class="tab-wizard wizard-circle form-horizontal floating-labels" role="form" name"this" id"this" action="patients.php" method="post">
<!-- Step 1 -->
<h6><strong>Personal Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_sname" id="pat_sname" required><span class="bar"></span><label for="pat_sname">Surname :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_fname" id="pat_fname" required><span class="bar"></span><label for="pat_fname">First Name :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<select class="form-control p-0" name="pat_gender" id="pat_gender" required>
<option value=""></option>
<option value="M">Male</option>
<option value="F">Female</option>
</select><span class="bar"></span>
<label for="pat_gender">Gender :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="date" class="form-control" name="pat_dob" id="pat_dob" required><span class="bar"></span><label for="pat_dob">D.O.B :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="tel" class="form-control" name="pat_phone" id="pat_phone" required><span class="bar"></span><label for="pat_phone">Phone :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="email" class="form-control" name="pat_email" id="pat_email" required><span class="bar"></span><label for="pat_email">Email :</label>
</div>
</div>
</div>
</section>
<!-- Step 2 -->
<h6><strong>Health Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<select class="form-control p-0" name="insurance_companies" id="insurance_companies" required>
<option value=""></option>
<option value="AAR">AAR</option>
<option value="AIG">AIG</option>
<option value="Britam">Britam</option>
<option value="IAA">IAA</option>
<option value="ICEA">ICEA</option>
<option value="Goldstar">Goldstar</option>
<option value="Liberty">Liberty</option>
<option value="NIC">NIC</option>
<option value="Sanlam">Sanlam</option>
<option value="SWICO">SWICO</option>
<option value="UAP">UAP</option>
</select><span class="bar"></span>
<label for="insurance_companies">Insurance Co.</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="card_no" id="card_no" required><span class="bar"></span><label for="card_no">Insurance Card No.</label>
</div>
</div>
<div class="col-md-12">
<div class="form-group m-t-20">
<textarea class="form-control" rows="1" id="pat_allergies" required></textarea>
<span class="bar"></span>
<label for="pat_allergies">Allergies :</label>
</div>
</div>
<div class="col-md-12">
<div class="form-group m-t-20">
<textarea class="form-control" rows="1" id="pat_history" required></textarea>
<span class="bar"></span>
<label for="pat_history">Medical History :</label>
</div>
</div>
</div>
</section>
<!-- Step 3 -->
<h6><strong>Home Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_address" id="pat_address" required><span class="bar"></span><label for="pat_address">Full Address :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="nok_name" id="nok_name" required><span class="bar"></span><label for="nok_name">Next of Kin :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="tel" class="form-control" name="nok_phone" id="nok_phone" required><span class="bar"></span><label for="nok_phone">Phone :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="email" class="form-control" name="nok_email" id="nok_email" required><span class="bar"></span><label for="nok_email">Email :</label>
</div>
</div>
<div class="col-md-12">
<div class="form-group m-t-20">
<textarea class="form-control" rows="1" id="pat_dependants" required></textarea>
<span class="bar"></span>
<label for="pat_dependants">Dependants :</label>
</div>
</div>
</div>
</section>
<!-- Step 4 -->
<h6><strong>Work Info</strong></h6>
<section>
<div class="row">
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_work" id="pat_work" required><span class="bar"></span><label for="pat_work">Place of Work :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="text" class="form-control" name="pat_work_address" id="pat_work_address" required><span class="bar"></span><label for="pat_work_address">Full Address :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="tel" class="form-control" name="work_phone" id="work_phone" required><span class="bar"></span><label for="work_phone">Phone :</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group m-t-20">
<input type="email" class="form-control" name="work_email" id="work_email" required><span class="bar"></span><label for="work_email">Email :</label>
</div>
</div>
</div>
</section>
</form>
</div>
</div>
</div>
</div>
</div>
and this my script:
$(".tab-wizard").steps({
headerTag: "h6"
, bodyTag: "section"
, transitionEffect: "fade"
, titleTemplate: '<span class="step">#index#</span> #title#'
, labels: {
finish: 'Finish'
},
onFinished: function (event, currentIndex) {
swal({
type: "success",
title: "Good Job!",
text: "You have successfully added a new patient.",
});
var form = $(this);
form.submit();
},
});
Below is my html table:
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-block">
<div class="table-responsive">
<!--<div class="col-md-12 align-self-center">
<button class="btn pull-right hidden-sm-down btn-danger m-l-5" id="deletebutton" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-delete"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-info m-l-5" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-pen"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-warning m-l-5" type="button" data-toggle="modal" data-target="#doc_view_modal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-information-outline"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-primary m-l-5" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-cash-multiple"></i></button></a>
<button class="btn pull-right hidden-sm-down btn-success m-l-20" type="button" data-toggle="modal" data-target="#adddoctormodal" data-original-title="View" data-whatever="#mdo"><i class="mdi mdi-calendar-plus"></i></button></a>
</div> -->
<table id="patientstable" class="display nowrap table table-hover table-striped table-bordered m-t-20" width="100%" cellspacing="0">
<thead>
<tr>
<th class="text-center">ID</th>
<th>Surname</th>
<th>First Name</th>
<th class="text-center">D.O.B</th>
<th class="text-center" >Gender</th>
<th class="text-center">Phone</th>
<th style="width: 100px;"></th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM patients";
$run_sql = mysqli_query($conn,$sql);
while ($rows = mysqli_fetch_array($run_sql)){
echo '
<tr>
<td class="text-center">'.$rows['id'].'</td>
<td>'.$rows['first_name'].'</td>
<td>'.$rows['surname'].'</td>
<td class="text-center">'.$rows['dateofbirth'].'</td>
<td class="text-center">'.$rows['gender'].'</td>
<td class="text-center">'.$rows['phone'].'</td>
<td id="actionicons">
<a href="user_id='.$rows['id'].'" data-toggle="modal" data-target="#pat_view_modal"> <i class="mdi mdi-information-outline text-warning"></i>
</i>
<a href="#" data-toggle="tooltip" data-original-title="Delete"> <i class="mdi mdi-delete text-danger"></i>
</td>
</tr>
';}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
I am stuck at a point where now have to submit the form but i am unable to since i can't call/reference the finish submit using an name or id since i can't assign it one.
Please help. Thanks.
Brian Dx.
In your patients.php you can use:
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
instead of:
if(isset($_POST['submit']))
since you can't put a submit name in jquery steps.
<div class="modal fade validate" id="modal-6">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Edit Advertisement</h4>
<label class="idhere"><?php echo $id; ?></label>
</div>
<?php $sel = $d->select('advertisements', 'ad_id=12');
while ($result = mysqli_fetch_assoc($sel)) {
?>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Image Upload</label>
<div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;" data-trigger="fileinput">
<img src="<?php echo $result['photo']; ?>">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px"></div>
<div>
<span class="btn btn-white btn-file">
<span class="fileinput-new">Select image</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="advertise_photo" accept="image/*">
</span>
Remove
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info">Send</button>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
<?php } ?>
</div>
</div>
</div>
I am unable to set the value of input type=file from database,
and if the image is exits then change button appear instead of select image.
when i am choosing new file it works properly,and change and remove button appear instead of select file.
Please help me to solve it.
Note: Above question is continuous of this question so the following answer is also continuous of this answer
You can skip the <label class="idhere"><?php echo $id;?></label>
in JS what yo need is ajax call method to fetch data from database against <?php $id;?> and display in modal
$(document).ready(function() {
$('#modal-6').on('shown.bs.modal', function(e) {
var id = $(e.relatedTarget).data('id');
$.ajax({
type : 'post',
url : 'file.php', //Here you will fetch records or images
data : 'id='+ id, //Pass id
success : function(data){
$('#fetched-data').html(data);//Show fetched data from database
}
});
});
});
Modal HTML will be
<div class="modal fade validate" id="modal-6">
<div class="modal-dialog">
<div class="modal-content">
<div id="fetched-data"></div>
</div>
</div>
</div>
and file.php will be
<?php
//database connection
if($_POST['id']) {
$id = $_POST['id']; //escape the string
//run query
//fetch data from database
//poplutae the HTML with values
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Edit Advertisement</h4>
</div>
<?php $sel = $d->select('advertisements','ad_id=12');
while($result = mysqli_fetch_assoc($sel)){
?>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Title</label>
<input class="form-control" value="<?php echo $result['title'];?>" name="advertise_title" data-validate="required" data-message-required="Please Enter Title" placeholder="Enter Title" type="text">
</div>
<div class="form-group col-md-6">
<label class="control-label">URL</label>
<input class="form-control" name="advertise_url" value="<?php echo $result['url'];?>" data-validate="required" data-message-required="Please Enter URL" placeholder="Enter URL" type="text">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group no-margin">
<label for="description" class="control-label">Description</label>
<textarea class="form-control autogrow" id="description" name="advertise_desc" placeholder="Describe Description Regarding Query">
<?php echo trim($result['description']); ?>
</textarea>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Image Upload</label>
<div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;" data-trigger="fileinput">
<img src="<?php echo $result['photo']; ?>">
<!-- <img src="images/thumbnail.jpeg" alt="..."> -->
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px"></div>
<div>
<span class="btn btn-white btn-file">
<span class="fileinput-new">Select image</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="advertise_photo" accept="image/*" >
</span>
Remove
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Active Flag</label>
<input type="checkbox">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info">Send</button>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
<?php } } ?>
As suggested by #devpro you need <form></form> to edit / update the populated data inside modal.
I have a following code with 5 file-upload buttons.
The 4 of them works properly, but when I insert the 5th upload button, my form is not submitted.
i.e. It redirects to the action page but isset() is not called.
HTML
<form action="g.php" method="post" enctype="multipart/form-data">
<div class="col-lg-4 ">
<div class="form-group">
<label for="InputName">Upload Photograph: </label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
<input type="file" name="stud_photo" id="stud_photo" required>
</span>
</span>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label for="InputName">Upload Course Admissoin Receipt: </label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
<input type="file" name="course_admission_receipt" id="course_admission_receipt" required>
</span>
</span>
</div>
</div>
</div>
<div class="col-lg-4 ">
<div class="form-group">
<label for="InputName">Upload Health Certificate: </label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
<input type="file" name="health_certificate" id="health_certificate" required>
</span>
</span>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="row">
<div class="col-lg-4 col-md-push-1">
<div class="form-group">
<label for="InputName">Upload Character Certificate: </label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
<input type="file" name="character_certificate" id="character_certificate" required />
</span>
</span>
</div>
</div>
</div>
<div class="col-lg-4 col-md-push-1">
<div class="form-group">
<label for="InputName">Upload Residence Certificate: </label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
<input type="file" name="resident_certificate" id="resident_certificate" />
</span>
</span>
</div>
</div>
<div>
</div> <!-- row-->
<div class="center">
<input type="submit" value="Submit Form" name="register" class="btn btn-default btn-lg">
</div>
</form>
PHP
<?php
echo "Im goin in <br>";
if(isset($_POST['register'])){
echo "im here";
}
else{
echo "I am not there";
}
?>
Only when I insert the last Upload Residence certificate button, It goes into else block.
Just above the submit button, You have an error in html,
<div> // this div should be a closing div
</div> <!-- row-->
Something like this,
</div>
</div> <!-- row-->
The mistake was neither in HTML code nor in PHP.
I checked my php.ini file and there I found this line
post_max_size = 3M
I changed it to
post_max_size = 30M
This means at max 30 Mb of data can be posed using $_POST method.
Since I was uploading images (800-1000kb) each, It was exceeding the max size.
Changing the value worked.
I'd like to prefill a form which should edit a entry in a database. When I click on 'Edit' within a row, a Modal should appear with the prefilled form. Everything is working fine so far, but I don't know how I have to change my code in order to get the Modal with the form prefilled.
<?php $page='database'; $php='yes'; $title='Datenbank' ; include( 'header.php'); ?>
<body>
<?php include( 'menu.php'); ?>
<div class="container">
<h1>Datenbank</h1>
<button class="btn btn-default" data-toggle="modal" data-target="#addToDatabase">Neuer Eintrag</button>
<br><br>
<p style="font-size: 16px; "><strong>Datenbankeinträge</strong></p>
<?php
$servername = "localhost";
$username = "xxx";
$password = "*******";
$dbname = "xxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, name, year, regie, actors, length FROM films";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<div style=\"overflow: auto\"><table> <tr> <th>ID</th> <th>Filmname</th> <th>Jahr</th> <th>Regie</th> <th>Schauspieler</th> <th>Länge [Minuten]</th> <th><a data-toggle=\"modal\" data-target=\"#updateDatabase \"><i class=\"glyphicon glyphicon-pencil\"></i></a></th> </tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row["id"];
echo "<tr><td>". $row["id"]. "</td><td>". $row["name"]. "</td><td>". $row["year"] . "</td><td>". $row["regie"] . "</td><td>". $row["actors"] . "</td><td>". $row["length"] . "</td><td><a data-toggle=\"modal\" data-target=\"#updateDatabase \"><i class=\"glyphicon glyphicon-pencil\"></i></td></tr>";
}
} else {
echo "Noch keine Einträge vorhanden. Bitte welche hinzufügen...";
}
echo "</table></div>";
$conn->close();
?>
<div id="addToDatabase" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Neuen Film zur Datenbank hinzufügen</h4>
</div>
<div class="modal-body">
<form method="post" action="insertAtDatabase.php">
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-film"></i></span>
<input type="text" name="name" class="form-control" placeholder="Filmname" value="1" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-calendar"></i></span>
<input type="number" name="year" class="form-control" placeholder="Erscheinungsjahr" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-star"></i></span>
<input type="text" name="regie" class="form-control" placeholder="Namen der Regie" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" name="actors" class="form-control" placeholder="Namen der Schauspieler" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-time"></i></span>
<input type="number" name="length" class="form-control" placeholder="Länge in Minuten" aria-describedby="basic-addon1">
</div>
<button type="submit" name="submit" class="btn btn-default margin-form">Übermitteln</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
</div>
</div>
</div>
</div>
<div id="updateDatabase" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Eintrag ändern</h4>
</div>
<div class="modal-body">
<form method="post" action="updateAtDatabase.php">
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-wrench"></i></span>
<input type="number" name="id" class="form-control" placeholder="ID" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-film"></i></span>
<input type="text" name="name" class="form-control" placeholder="Filmname" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-calendar"></i></span>
<input type="number" name="year" class="form-control" placeholder="Erscheinungsjahr" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-star"></i></span>
<input type="text" name="regie" class="form-control" placeholder="Namen der Regie" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" name="actors" class="form-control" placeholder="Namen der Schauspieler" aria-describedby="basic-addon1">
</div>
<div class="input-group margin-form">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-time"></i></span>
<input type="number" name="length" class="form-control" placeholder="Länge in Minuten" aria-describedby="basic-addon1">
</div>
<button type="submit" name="submit" class="btn btn-default margin-form">Übermitteln</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
</div>
</div>
</div>
</div>
</div>
<?php include( 'footer.php'); ?>
</body>
What else you need to know:
I am using the latest version of Bootstrap in order to get the Modal
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.