how to access value which passed through url? - php

I have trying to access value of variable from one page to another by using following code:-
page1.php
<td>
echo $var12=$row['p_id'];
echo 'Received';
</td>
receive_branch_confirmation.php
<?php echo $_GET['prop_id']; ?>
My previous error solved but now it is just print ",$var12,"
please tell me where is my mistake

As you are using echo for displaying the a tag you no need to use echo or close and open php tags.
It is enough if you concatenate the variable that you are going to send.
$var12 = '2';
echo 'Received';
Then your URL will look like as follows
http://domain.com/receive_branch_confirmation.php?prop_id=2
And in the receive_branch_confirmation.php you can access the variable passed with the help of $_GET or $_REQUEST
<?php
echo 'Request Value: '.$prop_id = $_REQUEST['prop_id']; // this will result the output as 2
echo '<br>';
echo 'Get Value'.$prop_id = $_GET['prop_id']; // this will result the output as 2
?>
Output:
Request Value: 2
Get Value: 2
Another Example:
If the URL is http://domain.com/page.php?var1=apple
then if you need to access the variable as follows in page.php.
<?php
$u1 = $_GET['var1'];
$u2 = $_REQUEST['var1'];
echo $u1; //would output "apple"
echo $u2; //would output "apple"
?>

page1.php
<td>
<?php echo '<a href=receive_branch_confirmation.php?prop_id='.$var12.'>Received</a>'; ?>
</td>
receive_branch_confirmation.php
<?php
echo $_GET['prop_id'];
?>

It should be
Received
in html page and
<?php
echo $_GET['prop_id'];
?>
in php page
and always try to separate html from PHP

You need to update your page1.php as below
echo 'Received';
and get it like this
<?php
echo $_GET['prop_id'];
?>

Try this in html
<td>
<a href="receive_branch_confirmation.php?prop_id="<?php echo $var12;?>>Received</a>
</td>
in php side
<?php
echo $_GET['prop_id'];
?>

You need to change the $_GET value.
<?php
echo $_GET['prop_id'];
?>
Now it's looking for the prop_id instead of the value

Related

how to add echo variable inside other variable from other file?

I am making static php and i want somthing like this (i am a php beginner :):
From this:
<?php $titleid="example title"; ?>
To this:
<?php $title="<?php echo $titleid; ?>"; ?>
To get this:
<h1><?php echo $title; ?></h1>
And then, the expected output is:
<h1>example title</h1>
I use this cause the variable $titleid is in other php file.
In this line
<?php $title="<?php echo $titleid; ?>"; ?>
You should not use the echo, since at that time you don't want any output. Also avoid the double <?php ?> brackets.
Just write that line as
<?php $title=$titleid; ?>
First, you open <?php tag only once in file. if you want get example title in your pages, you define this content one variable and then get result with echo :
Ex
<?php
$title = "<h1>example title</h1>";
echo $title;

creating a space before a variable including htmlencode str_repeat

I have a variable given to me by my cms
I want to add one space before that but have tried many things lol and all dont work, below is what I have tried so far.
<?php echo str_repeat('', 1) htmlencode('$postcode_coveringsRecord['postcode']) ?>
<?php echo htmlencode('&nbsp$postcode_coveringsRecord['postcode']) ?>
<?php echo htmlencode('. $postcode_coveringsRecord['postcode'].) ?>
<?php echo '&nbsp''htmlencode('$postcode_coveringsRecord['postcode'])' ?>
<?php echo htmlencode('&nbsp''$postcode_coveringsRecord['postcode']) ?>
How can I minipulate
where as the variable gives me one blank space prior to the variable content.
cheers for any input
emma
These ones should work
echo ' '.htmlencode($postcode_coveringsRecord['postcode']);
or
echo ' '.htmlencode($postcode_coveringsRecord['postcode']);

Syntax for using echo inside an echo (wordpress slider)

this is the piece of code I'm not sure how to deal with:
<?php echo get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="InsertHere"]'); ?>
I simply want to insert the first echo instead of InsertHere. The first echo should output the content of a custom field. The second should recall the slider with the specific number inserted in the custom field. When trying different possibilities I only get errors.
Can anybody help?
Thank you :)
Don't echo the first value, use it directly inside your second echo.
<?php
echo do_shortcode('[smartslider2 slider="'.get_post_meta($post->ID, 'smartslider2', true).'"]');
?>
Or you can easily put that first value in a variable and use that variable in the second line
<?php $slider = get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="'.$slider.'"]'); ?>

echo in an echo

I have the 2 following echos :
<?php echo $data->county; ?>
This one gives me datas like "florida", "california"... from the database
and
<?php echo lang(california); ?>
This one gives me a translation from a lang.php file, for example :
'california' => 'La californie'
I would like to place the $data->county in the lang echo, I tried the following with no success :
<?php echo lang(.$data->county.); ?>
What's the error ? Is it possible to echo in an echo ?
What made you think you needed the dots? Just pass it like any other argument:
<?php echo lang($data->county); ?>
<?php echo lang($data->county); ?>
Lose the .s, they're for concatenating strings. You're just passing a string variable.

How to set and get values from an url

I would like to set values on an url like this:
<a href='http://$data_url/viewyournote.php?chapter='$name_of_chapter'&note='$id_note'&user='$username'>
Then be able to grab then from the recieving page.
Right now all im getting is this when clicked:
http://localhost/readnotes/viewyournote.php?chapter=
I don't how you embed your link in your code, but if it is outside of <?php ?> tags, then you have to do:
<a href="http://<?php echo $data_url ?>/viewyournote.php?chapter=<?php echo $name_of_chapter ?>&note=<?php echo $id_note ?>&user=<?php echo $username?>" >
if it is inside these tags, you can also do:
echo "<a href='http://$data_url/viewyournote.php?chapter=$name_of_chapter&note=$id_note&user=$username?' >";
You can get these values on the recieveing page with $_GET['variable_name_here'], e.g. $_GET['chapter'].
Use Query string
$val = "yourvalue" ;
$url "http://localhost/readnotes/viewyournote.php?chapter=$val";
Now $val is passed to specified url .
There you could get it by using $_GET['chapter'] , It will give you "yourvalue"
<a href='http://$data_url/viewyournote.php?chapter=<?php echo $name_of_chapter; ?>&note=<?php echo $id_note; ?>&user=<?php echo $username; ?>>
Replace your line with
<?php
echo "<a href='http://$data_url/viewyournote.php?chapter='$name_of_chapter'&note='$id_note' user='$username'>";
?>
On the receiving end use
<?php
$name_of_chapter = $_GET['chapter'];
...
?>

Categories