0

the session value should be ok, but I could not retrieve in window.location, can someone help?

echo "<script>window.location='index.php?' + 'gp_name=' + '<?php echo $gname';?>'</script>";

code:

require_once 'connection.php';
session_start();
$gname = $_SESSION['gp_name'];

if(ISSET($_POST['submit'])){
    if($_FILES['upload']['name'] != "") {
        $file = $_FILES['upload'];
        $file_name = $file['name'];
        $file_temp = $file['tmp_name'];$name = explode('.', $file_name);
        $path = "files/".$file_name;

        $conn->query("INSERT INTO `file` VALUES('', '$gname', '$name[0]', '$path')") or die(mysqli_error());

        move_uploaded_file($file_temp, $path);
        header("location:index.php");

    }else{
        echo "<script>alert('Required Field!')</script>";
        echo "<script>window.location='index.php?' + 'gp_name=' + '<?php echo $gname';?>'</script>";
    }
}
Til
  • 5,150
  • 13
  • 26
  • 34
henrik
  • 43
  • 1
  • 8
  • You can't use php tags in javascript. `echo ""` is a non sense. – Cid Feb 05 '19 at 10:36
  • 1
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Cid Feb 05 '19 at 10:37
  • echo ""; do not echo php code as you have done. It will not be executed on client side – Viktar Pryshchepa Feb 05 '19 at 10:47

0 Answers0