Im trying to make the modal show in the condition is met but the problem is no modal is showing, can someone help me about this? The php code is below of the modal code.
here's the php
<?php
session_start();
include_once("connection.php");
if (isset($_POST['login']))
{
$stud_no = $_POST["stud_no"];
$password = $_POST["pword"];
$name = mysqli_real_escape_string($con, $stud_no);
$password = mysqli_real_escape_string($con, $password);
$select_user = "SELECT * FROM student_accounts WHERE stud_no ='$stud_no' AND password ='$password'";
$run_user = mysqli_query($con, $select_user);
$check_user = mysqli_num_rows($run_user);
if ($check_user > 0)
{
$_SESSION['stud_no'] = $stud_no;
header('location: home.php');
}
else
{
echo '<script>$("#myModal").modal()</script>';
}
}
?>
here's the modal
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
You just need to INCLUDE jQuery library before PHP code run, as well as bootstrap JS. And see the results, it will worked.
IF still not worked use below code to echo your script::
echo '<script type="text/javascript">'
. '$( document ).ready(function() {'
. '$("#myModal").modal("show");'
. '});'
. '</script>';
Replace below line
echo '<script>$("#myModal").modal()</script>';
with
echo '<script>$("#myModal").modal('show')</script>';
First include JQUERY CDN in the tags
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
if (condition === true) //Strict comparison
$(document).ready(function(){
$('#form').modal('show');
});
else
......
N/B #form is the ID for the modal
Related
I have a modal script that I created in php and the script works fine but the php closing tag ?> is not closing at the end, tried putting the script in the header using echo but then the script dose not work at all also tried using just php removing the Script tags that did not work been working on for a while any help would be greatly appreciated.
<?php
include("db_config.php");
include('includes/session.inc');
$Title = _('Check Inquiry');
$ViewTopic = 'AccountsPayable';
$BookMark = 'AccountsPayable';
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
echo '<link href="' . $RootPath . '/css/bootstrap.min.css" rel="stylesheet" type="text/css" />';
echo '<script src = "'.$RootPath.'/javascripts/jquery.min.js"></script>';
echo '<script type="text/javascript" src = "'.$RootPath.'/javascripts/bootstrap.min.js"></script>';
$query = "select * from banktrans where type=".'22';
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result)){
$transID = $row['transno'];
echo "<tr>";
echo "<td><button data-id='".$transID."' class='btn btn-info btn-sm btn-popup'>Details</button></td>";
echo "</tr>";
}
echo <<<'HTML'
<!-- Modal -->
<div class="modal fade" id="custModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Check Details</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('.btn-popup').click(function () {
var transno = $(this).data('id');
$.ajax({
url: 'get_check_data.php',
type: 'post',
data: { transno: transno },
success: function (response) {
$('.modal-body').html(response);
$('#custModal').modal('show');
}
});
});
});
</script>
HTML;
include('includes/footer.inc');
?>
Yes it dose appear I added the HTML in a separate php file and it works but the closing tag ?> is still not working as expected normally it shows up in NP++ in red when closed but shows as normal text but does not appear on page I am just wondering if it will create any issues that way.
Here is the code for the include modal.php
echo <<<'HTML'
<!-- Modal -->
<div class="modal fade" id="custModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Check Details</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('.btn-popup').click(function () {
var transno = $(this).data('id');
$.ajax({
url: 'get_check_data.php',
type: 'post',
data: { transno: transno },
success: function (response) {
$('.modal-body').html(response);
$('#custModal').modal('show');
}
});
});
});
</script>";
HTML;
?>'''
This is my code, i was supposed to get the "$pw" outside the modal.. But it seems that i can't get the value of it and Also i can't seem to fetch the "$errMSG" value.. If it's if($pin != $pww) cant get the err MESSAGE.. Really need some help.. Thank you!
This is my "$pw" code, its on the same page as my modal..
<?php
include('connectdb.php');
$sql = "SELECT * FROM accounts WHERE usernamee='$userid'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($data = $result->fetch_assoc()) {
$pww = $data['passwordd'];
}
}
?>
This is my modal code:
<div class="container">
<form method="post">
<h2>Enter your Pin Number</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Enter your Pin Number</h4>
</div>
<div class="modal-body text-center">
<input type="password" id="first-name" required="required" class="form-control" name="pin">
<?php
if(isset($errMSG)){
?>
<div class="alert alert-danger">
<span class="glyphicon glyphicon-infos-sign"></span> <strong><?php echo $errMSG; ?></strong>
</div>
<?php
}
else if(isset($successMSG)){
?>
<div class="alert alert-success">
<strong><span class="glyphicon glyphicon-info-sign"></span> <?php echo $successMSG; ?></strong>
</div>
<?php
}
?>
</div>
<div class="modal-footer">
<button type="submit" name="submit3" class="btn btn-default"><i class="fa fa-key"></i> Confirm Pin</button>
</div>
</div>
</div>
</div>
<!-- START OF PHP -->
<?php include ('connectdb.php');
if(isset($_POST['submit3']))
{
$pin = $_POST["pin"];
if ($pin != $pww) {
$errMSG= "WRONG PIN.. TRY AGAIN..";
}
else{
header('Location: myorders.php');
}
} // SUBMIT
?>
</form>
</div>
include('connectdb.php');
$pww = '';
$sql = "SELECT * FROM accounts WHERE usernamee='$userid'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($data = $result->fetch_assoc()) {
$pww = $data['passwordd'];
}
}
Try this code, You should declare pww before your if or while brackets, to get acces to this variable.
I would to fetch the mysql database table rows and display it into the html tables after that when user click on the value in table, bootstrap modal trigger and display all the column values of that clicked row in modal.
Here is php code
<tbody>
<?php
include "connection.php";
$sql="SELECT email,date_t from users";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result))
{
$mail=$row['email'];
$getID = mysqli_fetch_assoc(mysqli_query($conn, "SELECT fname,email from users where email='$mail'"));
$fname = $getID['fname'];
$email = $getID['email'];
echo '<tr>
<td>'.$fname.'</td>
<td>'.$row['email'].'</td>
<td>'. "$email" .'</td>
<td>'.$row['date_t'].'</td>
</tr>';
}
?>
</tbody>
Here is bootstrap modal
<div id="mymodel" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Email Reply</h4>
</div>
<div class="modal-body">
<p><?php echo $email; echo $fname; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
It will display value of $fname in modal but not display the value of $email
Any help will be appreciated!
I would like to have a popup windows on screen if a variable is set to 1, Im using PHP to load the page. So lets say I have the variable $Flag. on page load if the variable is 1 show the popup until the user click close. if $flag is set to 0 load the page as normal.
Im able to create a modal for the pop up and get the variable from the database, but how can i put those 2 together?
PHP Code:
if(isset($_SESSION['CurrentUser'])) {
$AppID=$_SESSION['CurrentUser'];
$ApplicantDetailsSQL=mysql_query("SELECT Accepted FROM Applicant WHERE AppID = '$AppID'");
$ApplicantDetails = mysql_fetch_assoc($ApplicantDetailsSQL);
if ($ApplicantDetails['Accepted'] == '1') {
//Show modal
}
}
HTML Code:
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
The HTML Modal is copy/paste from W3School.
Solution PHP:
if(isset($_SESSION['CurrentUser'])) {
$AppID=$_SESSION['CurrentUser'];
$ApplicantDetailsSQL=mysql_query("SELECT Accepted FROM Applicant WHERE AppID = '$AppID'");
$ApplicantDetails = mysql_fetch_assoc($ApplicantDetailsSQL);
if ($ApplicantDetails['Accepted'] == '1') {
$modal = true;
}
else{
$modal = false;
}
}
HTML:
<?php if($modal)
echo "<script type='text/javascript'> $(window).load(function(){ $('#myModal').modal('show'); }); </script>";
?>
</div> <!-- /container -->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">You are already a student</h4>
</div>
<div class="modal-body">
<p>You have already been accepted to one of our courses. This website is for application puproses only.</p>
<p>Since you are already a student, most of the functionality has been disabled for your account. Please login to the university's student portal for further.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
i have a page(products.php) that has a table which is dynamically populated. Each row has a button that opens up a modal, but in order to pass params to the modal: firstly, i declared the modal on the current page(products.php). Secondly, i call up the rest of the modal using ajax from another page(modal.php). i've popuplated all options in a select drop down before using ajax, but i can't seem to do the same this time by displaying the modal. i can use php href but that causes my jquery script that i use in submitting to the database on my modal not to work anymore and that's why i thought up doing this through ajax. I would like to know why this isn't working with well ajax.
Heres a sample code:
products.php
<html>
<header>
<script>
function modalValues(val1,val2){
if(window.XMLHttpRequest){
xhttp = new XMLHttpRequest();
}else{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function(){
if(xhttp.readyState == 4 && xhttp.status == 200){
document.getElementById("load_here").innerHTML = xhttp.responseText;
}
};
xhhtp.open("POST","modal.php?id3="+val1+"&id="+val2,true);
xhttp.send();
}
</script>
</header>
<body>
<div class="modal fade" data-keyboard="false" id="product_customerModal" tabindex="-1" role="dialog" aria-labelledby="product_customerModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div id="load_here" class="modal-content">
</div>
</div>
</div>
<table>
<?php
global $link;
$query = "blah,blah";
$result_set = mysqli_query($link,$query);
$number = mysqli_num_rows($result_set);
for($count=0;$count<$number;$count++){
$result = mysqli_fetch_array($result_set);
echo "<tr>";
echo "<td>{$result['field1']}</td>";
echo "<td>{$result['field2']}</td>";
echo "<td><button onclick='modalValues(<?php echo $result['field1'];?>,<?php echo $result['field2'];?>) data-toggle="modal" data-target='#product_customerModal'></button></td>";
}
?>
</table>
</body>
</html>
And
modal.php
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" > Date: (<?php echo $date;?>)</h4></div
<div class="modal-body">
<?php
//some php code
?>
<div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
You need to correct two lines they are as follows and then your model html will be there:
xhttp.open("POST","test2.php?id3="+val1+"&id="+val2,true); not xhttp
echo "<td><button onclick='modalValues('".$result['field1']."','".$result['field2']."') data-toggle='modal' data-target='#product_customerModal'></button></td>";