Welcome Guest ( Log In | Register )

Bump Topic Topic Closed RSS Feed

Outline · [ Standard ] · Linear+

 alert box after query, not sure why it did not work

views
     
TSMasafum1
post May 26 2016, 12:15 PM, updated 8y ago

Getting Started
**
Junior Member
208 posts

Joined: Jun 2013


hi, its me again. thanks to everyone who help me previously.
now i am back with some other problem.

right now, what i am trying to do is that after my form has finish query and insert the data to database, it will create a popup box that will popup that they have finish registering. after that they will be redirected back to homepage.

below is my code (short version of it)

CODE

<?php
$prm =
[
':nama' => $_POST['nama'],
':ic' => $_POST['ic'],
];

$sql = "INSERT INTO exam (nama,ic) VALUES (:nama,:ic)";

$qry = $conn->prepare($sql);
$qry->execute($prm);
?>
<script type="text/javascript">
alert('Tahniah, anda sudah memohon untuk peperiksaan);
</script>
<?php
header("location:index.php");
?>


but the problem is that after it finish query (and the data has been entered to database) no pop up shows up and the page is immediately redirected to homepage. So what did i do wrong? because i look up at w3school and i believe my script to show alert is correct.

hope sifu2 can help me.. (codemaster is for me a malaysia stack overflow)
summoning @ungka @alien3d @Eulm

ps: how do we tag someone here at this forum?
mcblade
post May 26 2016, 12:18 PM

New Member
******
Senior Member
1,116 posts

Joined: Jan 2003
From: Kuching, Sarawak
u missed one single quote on the end of your alert.

try comment out
<?php
header("location:index.php");
?>

and check whether alert work or not
TSMasafum1
post May 26 2016, 12:45 PM

Getting Started
**
Junior Member
208 posts

Joined: Jun 2013


QUOTE(mcblade @ May 26 2016, 12:18 PM)
u missed one single quote on the end of your alert.

try comment out
<?php
header("location:index.php");
?>

and check whether alert work or not
*
hi, i have comment out the header and have put the quote at the end of the alert

result:
the alert works. however when later i enable the header, after query, it immediately goes to index.php and did not pop up any alert.

thank you for replying notworthy.gif

any idea what should i do next
Trezzec
post May 26 2016, 01:02 PM

New Member
*
Junior Member
46 posts

Joined: Jan 2003
<script type="text/javascript">
alert('Tahniah, anda sudah memohon untuk peperiksaan);
</script>
<?php
header("location:index.php");
?>

remove and change to

echo "<script type='text/javascript'>
alert('Tahniah, anda sudah memohon untuk peperiksaan');
window.location.replace(\"/index.php\");
</SCRIPT>";
TSMasafum1
post May 26 2016, 01:25 PM

Getting Started
**
Junior Member
208 posts

Joined: Jun 2013


QUOTE(Trezzec @ May 26 2016, 01:02 PM)
<script type="text/javascript">
alert('Tahniah, anda sudah memohon untuk peperiksaan);
</script>
<?php
header("location:index.php");
?>

remove and change to

echo "<script type='text/javascript'>
  alert('Tahniah, anda sudah memohon untuk peperiksaan');
  window.location.replace(\"/index.php\");
  </SCRIPT>";
*
hi, thanks for replying

when i do as you suggested it produce an error

Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\bpmi\examregform.php on line 55

here is the code at line 52 - 58
CODE

$qry = $conn->prepare($sql);
$qry->execute($prm);
echo "
<script type="text/javascript">
window.alert('Tahniah, anda sudah memohon untuk peperiksaan');
window.location.replace(\"/index.php\");
</script>";



previously to counter the error, the only way working is by me closing the php .... however when i later do that technique on your code

CODE

$qry = $conn->prepare($sql);
$qry->execute($prm);
?> --- closing php here
<script type="text/javascript">
window.alert('Tahniah, anda sudah memohon untuk peperiksaan');
window.location.replace("index.php");
</script>



this make it works thumbup.gif rclxm9.gif rclxm9.gif

thank you Trezzec and mcblade.. the code is working. you guys are the best

Trezzec
post May 26 2016, 01:28 PM

New Member
*
Junior Member
46 posts

Joined: Jan 2003
$qry = $conn->prepare($sql);
$qry->execute($prm);
echo "
<script type="text/javascript">
window.alert('Tahniah, anda sudah memohon untuk peperiksaan');
window.location.replace(\"/index.php\");
</script>";
?> <-- put it in here. biggrin.gif
TSMasafum1
post May 26 2016, 01:36 PM

Getting Started
**
Junior Member
208 posts

Joined: Jun 2013


QUOTE(Trezzec @ May 26 2016, 01:28 PM)
$qry = $conn->prepare($sql);
$qry->execute($prm);
echo "
<script type="text/javascript">
window.alert('Tahniah, anda sudah memohon untuk peperiksaan');
window.location.replace(\"/index.php\");
</script>";
?> <-- put it in here. biggrin.gif
*
haha, apparently when i do like that an error came out

Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';'

the only way the code is working by closing the php and added the script at the bottom.

hohoho.
mcblade
post May 27 2016, 08:34 AM

New Member
******
Senior Member
1,116 posts

Joined: Jan 2003
From: Kuching, Sarawak
some simple googled..

<script type="text/javascript">
alert('After this goes away, I will be redirected via JavaScript');
window.location = "http://www.google.com";
</script>

works on my side

ops...since u got it right already, gratz and can close thread

This post has been edited by mcblade: May 27 2016, 08:35 AM
TSMasafum1
post May 27 2016, 09:37 AM

Getting Started
**
Junior Member
208 posts

Joined: Jun 2013


QUOTE(mcblade @ May 27 2016, 08:34 AM)
some simple googled..

<script type="text/javascript">
alert('After this goes away, I will be redirected via JavaScript');
window.location = "http://www.google.com";
</script>

works on my side

ops...since u got it right already, gratz and can close thread
*
yes. will be closing thread (funny thing is that when i google most of the search result points me to jquery... most probably due to my bad keywords i guess)

Topic ClosedOptions
 

Change to:
| Lo-Fi Version
0.0140sec    0.38    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 09:01 AM