Seppo Kuusela Seppo Kuusela - 10 months ago 36
Javascript Question

Showing bootstraps modal after redicted to page

So i have been making a website where settings.php and saveSettings.php page where it insert $_POST functions to database.

Here is part of settings.php


<form action="saveSettings.php" method="POST">
<div class="form-group">
<textarea class="form-control no-resize" rows="4" id="profilecomment" name="profilecomment"></textarea>
<input type="submit" class="btn btn-success" name="submit" style="margin-top:10px" value="Submit" />


and here part of saveSettings.php

$userComment = $_POST["profilecomment"];

$updateComment = "UPDATE users SET comment = '$userComment' WHERE steamid = '$steamID' ";

header('Location: settings.php');

This is what i have tried:

I added my modal load script to settings.php page


And modal script:

<div class="modal fade" id="settingsSave" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<div class="modal-body">
<p>You have successfully saved your settings!</p>

I am not sure if it does not popup because of that

header('Location: settings.php');

I hope i can get some help.


First, please be aware of mysql Injection, I see you dont escape your POST parameters.

Do it like this:

$userComment = mysql_real_escape_string($_POST["profilecomment"]);

or use mysqli instead of mysql

To your question:


is wrong, you must use something like:

$( document ).ready(function() { <? if(isset($_GET['save'])){ echo "$('#settingsSave').modal('show');"; } ?> });

ans pass a parameter to your new location

header('Location: settings.php?save');