Anan
Anan

Reputation: 103

$_GET not working 30

I have a PHP page(PAGE a) which is embedded(included) another PHP(Page b). It contains a Calendar. I am trying to create a functionality where when the user clicks on a link of a Date, the URL gets redirected to the PHP page b. I have tried to pass the Date through the URL and retrieve it on the Page b using $_GET. But the $_GET[] does not give me the value though the URL shows the value of the date.

Is it necessary to wrote the $_GET code inside the FORM in page b????

Is there something that I am doing wrong? Please help.

here is code of Page a:

<br><p><a href = 'add_eventec.php?selDate = $selDate' >Add Event</p><br />

Code of Page b:

if (!empty( $_GET['selDate']) ){

                $selcDate = $_GET['selDate'];
                echo "This is ". $selcDate;
                //$selDate = $_GET['dateSel'];
            }else{

                echo "This is not workingggggg";
            }

Please let me know.

---Worked finally!!!

Upvotes: 0

Views: 135

Answers (6)

sourcecode
sourcecode

Reputation: 1802

this will not collect php variable,as this is only html ,you have to explicitly render your date var in php

<br><p><a href = 'add_eventec.php?selDate = $selDate' >Add Event</p><br />

you can try these 2 methods->
1.

<br><p><a href = 'add_eventec.php?selDate=<?php echo $selDate ?>' >Add Event</p><br />

2.

<?php
echo "<br><p><a href = 'add_eventec.php?selDate = $selDate' >Add Event</p><br />";
?>

Upvotes: 0

Ali
Ali

Reputation: 3461

<br><p><a href = 'add_eventec.php?selDate = $selDate' >Add Event</p><br />

Try removing the spaces so it becomes

<br><p><a href = "add_eventec.php?selDate=$selDate" >Add Event</p><br />

Upvotes: 0

Orangepill
Orangepill

Reputation: 24645

Code should be

<?php
echo "<br><p><a href='add_eventec.php?selDate=$selDate'>Add Event</p><br />";
?>

Upvotes: 1

Alexandre Danault
Alexandre Danault

Reputation: 8672

You need to enclose your $selDat variable in php tags so that it gets echoed in the HTML.

<a href = 'add_eventec.php?selDate=<?= $selDate ?>' >Add Event</a>

Upvotes: 0

dudewad
dudewad

Reputation: 13933

I could be wrong but spaces in your URL count as characters too. Re-format your URL to not have the spaces:

<br><p><a href = 'add_eventec.php?selDat=' . $selDate >Add Event</p><br />

Also note that when building URLs I try to avoid adding variables into the string- I concatenate. It is safer.

Lastly, the code above- is it inside an echo statement? If not it needs to be:

<br><p><a href = 'add_eventec.php?selDat=<?php echo $selDate;?>'>Add Event</p><br />

Upvotes: 3

centree
centree

Reputation: 2439

Try

if (isset($_GET['selDate'])) {

And if that doesn't work selDate probably isn't passing.

Try

print_r($_GET);

to check if it is

Upvotes: 0

Related Questions