How to separate the php code from html and the code will still work as it is working! And print the $selection error variable above the selection menuHow to call PHP function from string stored in a VariablePHP & Ajax - can i use POST to retrieve form value without reloadPost form input to PHP using AJAX for multiple autocomplete query conditionsHow to avoid some SQL queries in PHP?Wordpress customizer - replace text in get_theme_modHow to pass variables and data from PHP to JavaScript?How to get the parent div id in javaScript?Cannot display HTML stringHow do I display this array correctly in html?How to print HTML code in php
Variable does not Exist: CaseTrigger
A nasty indefinite integral
What is the winged creature on the back of the Mordenkainen's Tome of Foes book?
Is there a word for pant sleeves?
How to safely discharge oneself
Gas chromatography flame ionization detector (FID) - why hydrogen gas?
csname in newenviroment
Does attacking (or having a rider attack) cancel Charge/Pounce-like abilities?
Which are the advantages/disadvantages of includestandalone?
Why the work done is positive when bringing 2 opposite charges together?
How do I write real-world stories separate from my country of origin?
How do you earn the reader's trust?
Can a UK national work as a paid shop assistant in the USA?
Team member is vehemently against code formatting
Ribbon Cable Cross Talk - Is there a fix after the fact?
Illustrating that universal optimality is stronger than sphere packing
Is there a linguistic basses for how to translate John 8:43, or are translations basing their translation on context alone?
What defines a person who is circumcised "of the heart"?
What does it mean for something to be strictly less than epsilon for an arbitrary epsilon?
Why is Ni[(PPh₃)₂Cl₂] tetrahedral?
Salesforce bug enabled "Modify All"
Way of refund if scammed?
Is there any mention of ghosts who live outside the Hogwarts castle?
Download app bundles from App Store to run on iOS Emulator on Mac
How to separate the php code from html and the code will still work as it is working! And print the $selection error variable above the selection menu
How to call PHP function from string stored in a VariablePHP & Ajax - can i use POST to retrieve form value without reloadPost form input to PHP using AJAX for multiple autocomplete query conditionsHow to avoid some SQL queries in PHP?Wordpress customizer - replace text in get_theme_modHow to pass variables and data from PHP to JavaScript?How to get the parent div id in javaScript?Cannot display HTML stringHow do I display this array correctly in html?How to print HTML code in php
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to print the the $selection_error variable on top of the selection menu but it is not working there but if I print the $selection_error variable below the table it is working. Is there any way to separate the php code from html by placing it on top of all the html code so that I could print the $selection_error variable on top of the selection menu?
I'm trying to add this code below the h3 tag above the form..
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
not exactly below the table as it is shown in the code!
<?php include("includes/header.php"); ?>
<div id="wrapper">
<!-- Navigation -->
<?php include("includes/navbar.php"); ?>
<!--./Navigation -->
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">
<div class="text-center" style="letter-spacing: 1.5px;">
View Student Information
</div>
</h3>
<div class="formstyle">
<form class="form-inline st" action="" method="POST">
<label for="sel11" class="form-control-label ab">Select Semester</label>
<?php
$query = $connection->query("SELECT * FROM semester ORDER BY sem_id ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel11" name="sel11">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['sem_id'].'">'.$row['sem_name'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel12" class="form-control-label ab">Start Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_start) FROM student ORDER BY session_start ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel12" name="sel12">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_start'].'">'.$row['session_start'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel13" class="form-control-label ab">End Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_end) FROM student ORDER BY session_end ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel13" name="sel13">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_end'].'">'.$row['session_end'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<div class="ab inline">
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</div>
</form>
</div>
<input type="text" id="myInput" onkeyup="myFunction2()" placeholder="Search for roll no or names..">
<table class="table table-bordered table-hover" id="myTable">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Roll No</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Start Session</th>
<th scope="col">End Session</th>
<th scope="col">Semester</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$error = false;
if(isset($_POST['submit']))
if(isset($_POST['sel11']) && isset($_POST['sel12']) && isset($_POST['sel13']))
$sel11 = mysqli_real_escape_string($connection, $_POST['sel11']);
$sel12 = mysqli_real_escape_string($connection, $_POST['sel12']);
$sel13 = mysqli_real_escape_string($connection, $_POST['sel13']);
$query = "SELECT * FROM student, semester WHERE student.session_start = '$sel12' AND student.session_end = '$sel13' AND student.sem_id = semester.sem_id AND student.sem_id = '$sel11' ORDER BY student.s_rollno ASC";
$select_student_query = mysqli_query($connection, $query);
$rowCount = $select_student_query->num_rows;
if($rowCount > 0)
$i = 0;
while ($row = mysqli_fetch_assoc($select_student_query))
$s_id = $row['s_id'];
$s_rollno = $row['s_rollno'];
$s_email = $row['s_email'];
$s_name = $row['s_name'];
$session_start = $row['session_start'];
$session_end = $row['session_end'];
$sem_name = $row['sem_name'];
$i = $i + 1;
echo "<tr>";
echo "<th scope='row'>$i</th>";
echo "<td>$s_rollno</td>";
echo "<td>$s_name</td>";
echo "<td>$s_email</td>";
echo "<td>$session_start</td>";
echo "<td>$session_end</td>";
echo "<td>$sem_name</td>";
echo "<td>
<div class='btn-group'>
<a href='updateStudent.php?update=$s_id' class='btn btn-warning' role='button'>Edit</a>
<a href='viewStudentInfo.php?delete=$s_id' class='btn btn-danger' role='button'>Delete</a>
</div>
</td>";
echo "</tr>";
else
echo "<tr>";
echo "<td class='text-center' colspan='8'>";
echo "<h3 class='text-danger'>No Data Found!</h3>";
echo "</td>";
echo "</tr>";
else
$error = true;
$selection_error = "Select at least one option from each dropdown list!";
?>
</tbody>
</table>
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
<?php
if(isset($_GET['delete']))
$s_id = $_GET['delete'];
$query = "DELETE FROM student WHERE s_id = '$s_id'";
$delete_student_query = mysqli_query($connection, $query);
header("Location: viewStudentInfo.php");
?>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<?php include("includes/footer.php"); ?>
php html mysql
add a comment |
I want to print the the $selection_error variable on top of the selection menu but it is not working there but if I print the $selection_error variable below the table it is working. Is there any way to separate the php code from html by placing it on top of all the html code so that I could print the $selection_error variable on top of the selection menu?
I'm trying to add this code below the h3 tag above the form..
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
not exactly below the table as it is shown in the code!
<?php include("includes/header.php"); ?>
<div id="wrapper">
<!-- Navigation -->
<?php include("includes/navbar.php"); ?>
<!--./Navigation -->
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">
<div class="text-center" style="letter-spacing: 1.5px;">
View Student Information
</div>
</h3>
<div class="formstyle">
<form class="form-inline st" action="" method="POST">
<label for="sel11" class="form-control-label ab">Select Semester</label>
<?php
$query = $connection->query("SELECT * FROM semester ORDER BY sem_id ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel11" name="sel11">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['sem_id'].'">'.$row['sem_name'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel12" class="form-control-label ab">Start Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_start) FROM student ORDER BY session_start ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel12" name="sel12">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_start'].'">'.$row['session_start'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel13" class="form-control-label ab">End Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_end) FROM student ORDER BY session_end ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel13" name="sel13">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_end'].'">'.$row['session_end'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<div class="ab inline">
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</div>
</form>
</div>
<input type="text" id="myInput" onkeyup="myFunction2()" placeholder="Search for roll no or names..">
<table class="table table-bordered table-hover" id="myTable">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Roll No</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Start Session</th>
<th scope="col">End Session</th>
<th scope="col">Semester</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$error = false;
if(isset($_POST['submit']))
if(isset($_POST['sel11']) && isset($_POST['sel12']) && isset($_POST['sel13']))
$sel11 = mysqli_real_escape_string($connection, $_POST['sel11']);
$sel12 = mysqli_real_escape_string($connection, $_POST['sel12']);
$sel13 = mysqli_real_escape_string($connection, $_POST['sel13']);
$query = "SELECT * FROM student, semester WHERE student.session_start = '$sel12' AND student.session_end = '$sel13' AND student.sem_id = semester.sem_id AND student.sem_id = '$sel11' ORDER BY student.s_rollno ASC";
$select_student_query = mysqli_query($connection, $query);
$rowCount = $select_student_query->num_rows;
if($rowCount > 0)
$i = 0;
while ($row = mysqli_fetch_assoc($select_student_query))
$s_id = $row['s_id'];
$s_rollno = $row['s_rollno'];
$s_email = $row['s_email'];
$s_name = $row['s_name'];
$session_start = $row['session_start'];
$session_end = $row['session_end'];
$sem_name = $row['sem_name'];
$i = $i + 1;
echo "<tr>";
echo "<th scope='row'>$i</th>";
echo "<td>$s_rollno</td>";
echo "<td>$s_name</td>";
echo "<td>$s_email</td>";
echo "<td>$session_start</td>";
echo "<td>$session_end</td>";
echo "<td>$sem_name</td>";
echo "<td>
<div class='btn-group'>
<a href='updateStudent.php?update=$s_id' class='btn btn-warning' role='button'>Edit</a>
<a href='viewStudentInfo.php?delete=$s_id' class='btn btn-danger' role='button'>Delete</a>
</div>
</td>";
echo "</tr>";
else
echo "<tr>";
echo "<td class='text-center' colspan='8'>";
echo "<h3 class='text-danger'>No Data Found!</h3>";
echo "</td>";
echo "</tr>";
else
$error = true;
$selection_error = "Select at least one option from each dropdown list!";
?>
</tbody>
</table>
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
<?php
if(isset($_GET['delete']))
$s_id = $_GET['delete'];
$query = "DELETE FROM student WHERE s_id = '$s_id'";
$delete_student_query = mysqli_query($connection, $query);
header("Location: viewStudentInfo.php");
?>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<?php include("includes/footer.php"); ?>
php html mysql
WARNING: When usingmysqli
you should be using parameterized queries andbind_param
to add user data to your query. DO NOT use manual escaping and string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. Accidentally unescaped data is a serious risk. Using bound parameters is less verbose and easier to review to check you’re doing it properly.
– tadman
Mar 23 at 21:32
Note: The object-oriented interface tomysqli
is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_query
interface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)
and$db->prepare("…")
The procedural interface is an artifact from the PHP 4 era whenmysqli
API was introduced and ideally should not be used in new code. You're using both styles here inconsistently.
– tadman
Mar 23 at 21:32
🐘If you're just getting started with PHP and want to build applications, I'd also strongly recommend looking at various development frameworks to see if you can find one that fits your style and needs. They come in various flavors from lightweight like Fat-Free Framework to far more comprehensive like Laravel. These typically implement the Model-View-Controller pattern which provides better separation from code and HTML.
– tadman
Mar 23 at 21:33
add a comment |
I want to print the the $selection_error variable on top of the selection menu but it is not working there but if I print the $selection_error variable below the table it is working. Is there any way to separate the php code from html by placing it on top of all the html code so that I could print the $selection_error variable on top of the selection menu?
I'm trying to add this code below the h3 tag above the form..
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
not exactly below the table as it is shown in the code!
<?php include("includes/header.php"); ?>
<div id="wrapper">
<!-- Navigation -->
<?php include("includes/navbar.php"); ?>
<!--./Navigation -->
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">
<div class="text-center" style="letter-spacing: 1.5px;">
View Student Information
</div>
</h3>
<div class="formstyle">
<form class="form-inline st" action="" method="POST">
<label for="sel11" class="form-control-label ab">Select Semester</label>
<?php
$query = $connection->query("SELECT * FROM semester ORDER BY sem_id ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel11" name="sel11">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['sem_id'].'">'.$row['sem_name'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel12" class="form-control-label ab">Start Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_start) FROM student ORDER BY session_start ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel12" name="sel12">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_start'].'">'.$row['session_start'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel13" class="form-control-label ab">End Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_end) FROM student ORDER BY session_end ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel13" name="sel13">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_end'].'">'.$row['session_end'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<div class="ab inline">
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</div>
</form>
</div>
<input type="text" id="myInput" onkeyup="myFunction2()" placeholder="Search for roll no or names..">
<table class="table table-bordered table-hover" id="myTable">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Roll No</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Start Session</th>
<th scope="col">End Session</th>
<th scope="col">Semester</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$error = false;
if(isset($_POST['submit']))
if(isset($_POST['sel11']) && isset($_POST['sel12']) && isset($_POST['sel13']))
$sel11 = mysqli_real_escape_string($connection, $_POST['sel11']);
$sel12 = mysqli_real_escape_string($connection, $_POST['sel12']);
$sel13 = mysqli_real_escape_string($connection, $_POST['sel13']);
$query = "SELECT * FROM student, semester WHERE student.session_start = '$sel12' AND student.session_end = '$sel13' AND student.sem_id = semester.sem_id AND student.sem_id = '$sel11' ORDER BY student.s_rollno ASC";
$select_student_query = mysqli_query($connection, $query);
$rowCount = $select_student_query->num_rows;
if($rowCount > 0)
$i = 0;
while ($row = mysqli_fetch_assoc($select_student_query))
$s_id = $row['s_id'];
$s_rollno = $row['s_rollno'];
$s_email = $row['s_email'];
$s_name = $row['s_name'];
$session_start = $row['session_start'];
$session_end = $row['session_end'];
$sem_name = $row['sem_name'];
$i = $i + 1;
echo "<tr>";
echo "<th scope='row'>$i</th>";
echo "<td>$s_rollno</td>";
echo "<td>$s_name</td>";
echo "<td>$s_email</td>";
echo "<td>$session_start</td>";
echo "<td>$session_end</td>";
echo "<td>$sem_name</td>";
echo "<td>
<div class='btn-group'>
<a href='updateStudent.php?update=$s_id' class='btn btn-warning' role='button'>Edit</a>
<a href='viewStudentInfo.php?delete=$s_id' class='btn btn-danger' role='button'>Delete</a>
</div>
</td>";
echo "</tr>";
else
echo "<tr>";
echo "<td class='text-center' colspan='8'>";
echo "<h3 class='text-danger'>No Data Found!</h3>";
echo "</td>";
echo "</tr>";
else
$error = true;
$selection_error = "Select at least one option from each dropdown list!";
?>
</tbody>
</table>
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
<?php
if(isset($_GET['delete']))
$s_id = $_GET['delete'];
$query = "DELETE FROM student WHERE s_id = '$s_id'";
$delete_student_query = mysqli_query($connection, $query);
header("Location: viewStudentInfo.php");
?>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<?php include("includes/footer.php"); ?>
php html mysql
I want to print the the $selection_error variable on top of the selection menu but it is not working there but if I print the $selection_error variable below the table it is working. Is there any way to separate the php code from html by placing it on top of all the html code so that I could print the $selection_error variable on top of the selection menu?
I'm trying to add this code below the h3 tag above the form..
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
not exactly below the table as it is shown in the code!
<?php include("includes/header.php"); ?>
<div id="wrapper">
<!-- Navigation -->
<?php include("includes/navbar.php"); ?>
<!--./Navigation -->
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">
<div class="text-center" style="letter-spacing: 1.5px;">
View Student Information
</div>
</h3>
<div class="formstyle">
<form class="form-inline st" action="" method="POST">
<label for="sel11" class="form-control-label ab">Select Semester</label>
<?php
$query = $connection->query("SELECT * FROM semester ORDER BY sem_id ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel11" name="sel11">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['sem_id'].'">'.$row['sem_name'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel12" class="form-control-label ab">Start Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_start) FROM student ORDER BY session_start ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel12" name="sel12">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_start'].'">'.$row['session_start'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<label for="sel13" class="form-control-label ab">End Session</label>
<?php
$query = $connection->query("SELECT DISTINCT(session_end) FROM student ORDER BY session_end ASC");
$rowCount = $query->num_rows;
?>
<select class="form-control" id="sel13" name="sel13">
<option selected="selected" disabled="disabled">Select</option>
<?php
if($rowCount > 0)
while($row = $query->fetch_assoc())
echo '<option value="'.$row['session_end'].'">'.$row['session_end'].'</option>';
else
echo '<option value="">Semester not available</option>';
?>
</select>
<div class="ab inline">
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</div>
</form>
</div>
<input type="text" id="myInput" onkeyup="myFunction2()" placeholder="Search for roll no or names..">
<table class="table table-bordered table-hover" id="myTable">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Roll No</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Start Session</th>
<th scope="col">End Session</th>
<th scope="col">Semester</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$error = false;
if(isset($_POST['submit']))
if(isset($_POST['sel11']) && isset($_POST['sel12']) && isset($_POST['sel13']))
$sel11 = mysqli_real_escape_string($connection, $_POST['sel11']);
$sel12 = mysqli_real_escape_string($connection, $_POST['sel12']);
$sel13 = mysqli_real_escape_string($connection, $_POST['sel13']);
$query = "SELECT * FROM student, semester WHERE student.session_start = '$sel12' AND student.session_end = '$sel13' AND student.sem_id = semester.sem_id AND student.sem_id = '$sel11' ORDER BY student.s_rollno ASC";
$select_student_query = mysqli_query($connection, $query);
$rowCount = $select_student_query->num_rows;
if($rowCount > 0)
$i = 0;
while ($row = mysqli_fetch_assoc($select_student_query))
$s_id = $row['s_id'];
$s_rollno = $row['s_rollno'];
$s_email = $row['s_email'];
$s_name = $row['s_name'];
$session_start = $row['session_start'];
$session_end = $row['session_end'];
$sem_name = $row['sem_name'];
$i = $i + 1;
echo "<tr>";
echo "<th scope='row'>$i</th>";
echo "<td>$s_rollno</td>";
echo "<td>$s_name</td>";
echo "<td>$s_email</td>";
echo "<td>$session_start</td>";
echo "<td>$session_end</td>";
echo "<td>$sem_name</td>";
echo "<td>
<div class='btn-group'>
<a href='updateStudent.php?update=$s_id' class='btn btn-warning' role='button'>Edit</a>
<a href='viewStudentInfo.php?delete=$s_id' class='btn btn-danger' role='button'>Delete</a>
</div>
</td>";
echo "</tr>";
else
echo "<tr>";
echo "<td class='text-center' colspan='8'>";
echo "<h3 class='text-danger'>No Data Found!</h3>";
echo "</td>";
echo "</tr>";
else
$error = true;
$selection_error = "Select at least one option from each dropdown list!";
?>
</tbody>
</table>
<?php if (isset($selection_error))
print_r("<div class='alert alert-danger' role='alert'>
$selection_error <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button> </div>");
?>
<?php
if(isset($_GET['delete']))
$s_id = $_GET['delete'];
$query = "DELETE FROM student WHERE s_id = '$s_id'";
$delete_student_query = mysqli_query($connection, $query);
header("Location: viewStudentInfo.php");
?>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<?php include("includes/footer.php"); ?>
php html mysql
php html mysql
asked Mar 23 at 20:50
RamanathRamanath
11
11
WARNING: When usingmysqli
you should be using parameterized queries andbind_param
to add user data to your query. DO NOT use manual escaping and string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. Accidentally unescaped data is a serious risk. Using bound parameters is less verbose and easier to review to check you’re doing it properly.
– tadman
Mar 23 at 21:32
Note: The object-oriented interface tomysqli
is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_query
interface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)
and$db->prepare("…")
The procedural interface is an artifact from the PHP 4 era whenmysqli
API was introduced and ideally should not be used in new code. You're using both styles here inconsistently.
– tadman
Mar 23 at 21:32
🐘If you're just getting started with PHP and want to build applications, I'd also strongly recommend looking at various development frameworks to see if you can find one that fits your style and needs. They come in various flavors from lightweight like Fat-Free Framework to far more comprehensive like Laravel. These typically implement the Model-View-Controller pattern which provides better separation from code and HTML.
– tadman
Mar 23 at 21:33
add a comment |
WARNING: When usingmysqli
you should be using parameterized queries andbind_param
to add user data to your query. DO NOT use manual escaping and string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. Accidentally unescaped data is a serious risk. Using bound parameters is less verbose and easier to review to check you’re doing it properly.
– tadman
Mar 23 at 21:32
Note: The object-oriented interface tomysqli
is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_query
interface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)
and$db->prepare("…")
The procedural interface is an artifact from the PHP 4 era whenmysqli
API was introduced and ideally should not be used in new code. You're using both styles here inconsistently.
– tadman
Mar 23 at 21:32
🐘If you're just getting started with PHP and want to build applications, I'd also strongly recommend looking at various development frameworks to see if you can find one that fits your style and needs. They come in various flavors from lightweight like Fat-Free Framework to far more comprehensive like Laravel. These typically implement the Model-View-Controller pattern which provides better separation from code and HTML.
– tadman
Mar 23 at 21:33
WARNING: When using
mysqli
you should be using parameterized queries and bind_param
to add user data to your query. DO NOT use manual escaping and string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. Accidentally unescaped data is a serious risk. Using bound parameters is less verbose and easier to review to check you’re doing it properly.– tadman
Mar 23 at 21:32
WARNING: When using
mysqli
you should be using parameterized queries and bind_param
to add user data to your query. DO NOT use manual escaping and string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. Accidentally unescaped data is a serious risk. Using bound parameters is less verbose and easier to review to check you’re doing it properly.– tadman
Mar 23 at 21:32
Note: The object-oriented interface to
mysqli
is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete mysql_query
interface. Before you get too invested in the procedural style it’s worth switching over. Example: $db = new mysqli(…)
and $db->prepare("…")
The procedural interface is an artifact from the PHP 4 era when mysqli
API was introduced and ideally should not be used in new code. You're using both styles here inconsistently.– tadman
Mar 23 at 21:32
Note: The object-oriented interface to
mysqli
is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete mysql_query
interface. Before you get too invested in the procedural style it’s worth switching over. Example: $db = new mysqli(…)
and $db->prepare("…")
The procedural interface is an artifact from the PHP 4 era when mysqli
API was introduced and ideally should not be used in new code. You're using both styles here inconsistently.– tadman
Mar 23 at 21:32
🐘If you're just getting started with PHP and want to build applications, I'd also strongly recommend looking at various development frameworks to see if you can find one that fits your style and needs. They come in various flavors from lightweight like Fat-Free Framework to far more comprehensive like Laravel. These typically implement the Model-View-Controller pattern which provides better separation from code and HTML.
– tadman
Mar 23 at 21:33
🐘If you're just getting started with PHP and want to build applications, I'd also strongly recommend looking at various development frameworks to see if you can find one that fits your style and needs. They come in various flavors from lightweight like Fat-Free Framework to far more comprehensive like Laravel. These typically implement the Model-View-Controller pattern which provides better separation from code and HTML.
– tadman
Mar 23 at 21:33
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318240%2fhow-to-separate-the-php-code-from-html-and-the-code-will-still-work-as-it-is-wor%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318240%2fhow-to-separate-the-php-code-from-html-and-the-code-will-still-work-as-it-is-wor%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
WARNING: When using
mysqli
you should be using parameterized queries andbind_param
to add user data to your query. DO NOT use manual escaping and string interpolation or concatenation to accomplish this because you will create severe SQL injection bugs. Accidentally unescaped data is a serious risk. Using bound parameters is less verbose and easier to review to check you’re doing it properly.– tadman
Mar 23 at 21:32
Note: The object-oriented interface to
mysqli
is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_query
interface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)
and$db->prepare("…")
The procedural interface is an artifact from the PHP 4 era whenmysqli
API was introduced and ideally should not be used in new code. You're using both styles here inconsistently.– tadman
Mar 23 at 21:32
🐘If you're just getting started with PHP and want to build applications, I'd also strongly recommend looking at various development frameworks to see if you can find one that fits your style and needs. They come in various flavors from lightweight like Fat-Free Framework to far more comprehensive like Laravel. These typically implement the Model-View-Controller pattern which provides better separation from code and HTML.
– tadman
Mar 23 at 21:33