Seppo Kuusela Seppo Kuusela - 4 months ago 10
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

<?php

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

?>


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

<script>
$(window).load(function(){
$('#settingsSave').modal('show');
});
</script>


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>
<div class="modal-body">
<p>You have successfully saved your settings!</p>
</div>
</div>
</div>
</div>


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

header('Location: settings.php');


I hope i can get some help.

Answer

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:

$(window).load(function(){
       $('#settingsSave').modal('show');
 });

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');