-5

Want to fetch a number from a database and use that number to direct to a new page

$sql4="SELECT `level_crossed` FROM $tbl_name WHERE username='$myuser' and password='$mypass'";
$result4=mysql_query($sql4);
$disp4=mysql_fetch_assoc($result4);

header('Location: quiz".$disp4.".php'); 

Level crossed is of integer type. I want to redirect the current page to quiz1 or quiz2 or quiz 3 page depending on the value stored in level_crossed attribute.

But it is unable to redirect. URL coming up as http://treasurehunt.faltutalk.com/quiz%22.$result.%22.php

pallavi
  • 114
  • 1
  • 3
  • 9

3 Answers3

0

the string you use in the header function call has mixed quotes and thus it's wrong. You can choose one of the following:

first of all, get a normal string:

$str = $disp4['level_crossing'];

then choose:

header('Location: quiz'.$str.'.php'); 

or

header("Location: quiz$disp4.php"); 

or even

header("Location: quiz".$str.".php");   

next time, double check your quotes.

STT LCU
  • 4,348
  • 4
  • 29
  • 47
0

Change it to header("Location: quiz{$disp4['level_crossed']}.php");

Steely Wing
  • 16,239
  • 8
  • 58
  • 54
0

Swap out the double quotes for single quotes

Tralli
  • 398
  • 1
  • 2
  • 12