简体   繁体   English

我做错了什么$_GET

[英]What am I doing wrong $_GET

I am trying to get a value from a URL and it's not working.我正在尝试从 URL 获取值,但它不起作用。 Here is the code:这是代码:

<?php
if (isset($_GET['pag'])) {
    $sel_continut = $_GET['pag'];
} else {
    $sel_continut = "no value sent";
}

echo "<a href=\"continut.php?pag=" . $informatie_tabel['nume_meniu'] . "\">" . $denumire_pagina . "</a> <br />";

Can someone help me understand what I'm doing wrong?有人可以帮助我了解我做错了什么吗?

In response to your comments...回应您的评论...

This is the URL being used to load the page:这是用于加载页面的 URL:

http://localhost/extragere_din_baza_de_date.php

Note that there is no query string value .请注意,没有查询字符串值 So this code:所以这段代码:

$_GET['pag']

isn't going to find anything.不会找到任何东西。 The value was never set.该值从未设置。 So your code is always going to enter the else condition.所以你的代码总是会进入else条件。 You later create a link with a query string value:您稍后创建一个带有查询字符串值的链接:

http://localhost/continut.php?pag=Home

But that's for a completely different page which hasn't even been requested yet .但那是一个完全不同的页面,它甚至还没有被请求 If you reference $_GET['pag'] on the continut.php page's code, then you'll see the value.如果您在continut.php页面的代码中引用$_GET['pag'] ,那么您将看到该值。

What I'm trying to say is... You can't read a query string value before it's been sent.我想说的是...在发送之前您无法读取查询字符串值。 The good news is that you don't need to read this value.好消息是您不需要读取此值。 Since you're in the same code which sets the value on the link, then clearly you already have this value.由于您在相同的代码中设置链接上的值,因此显然您已经拥有此值。 Right here:就在这儿:

$informatie_tabel['nume_meniu']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM