0
Good evening guys ! I needed some help with the Alert(); , I’m trying to show off on the page index.html, one Alert(); showing that the data was inserted correctly, reading some posts on the forum, gave the idea of on the page index php. (where the data is processed) save the message to a $_SESSION and pull with JS la no HTML that value of $_SESSION. I tested the idea and the result was this:
PHP code:
$_SESSION['registro'] = "Seu gasto foi inserido corretamente!!";
header("location: index.html");
Code in the HTML
<script>alert(".$_SESSION['registro'];.");</script>
Remembering that I tried to change the "" to '', both from $_SESSION and Alert();
The result was :
The question is ... Where is the mistake? If there is no error, what alternative can I use to display this alert after the Insert made by index.php?
[RESOLVED]
I changed my index.html for index php. then added the following line of code :
<script>alert('<?php session_start();
if($_SESSION['registro']!=null)
{echo $_SESSION['registro'];}
?>');</script>
Important to point out that I was not putting the session_start();
And on my data loading page I added the value of $_SESSION
session_start();
if($_SESSION['registro'] == null){
$_SESSION['registro'] = "Registro cadastro com sucesso !";
}
header("location: index.php");
Talks Ustavo !! I did the test and it still didn’t work, even changing the extension to PHP and adding the php code
– Pedro Terencio - Gamer Artist
Are you using a personal server or are you hosting the web page? Whatever, there is PHP support, correct?
– Gustavo Sampaio
I’m using xampp to use on localhost
– Pedro Terencio - Gamer Artist
What value is coming out?
– Gustavo Sampaio
No value is coming out (printing nothing on the screen), I did the test on the same page, and it worked, however, I can not use the header to go to the home page, because if I use it Alert does not appear (visibly)
– Pedro Terencio - Gamer Artist
I added more information to the reply
– Gustavo Sampaio
Thanks !! worked out Gustavo !!
– Pedro Terencio - Gamer Artist