Passing URL does not output variable with echo - php

The link page:
<a href="displayProduct.php?productID=<?php'.$pID.'?>">
The displayProduct.php page:
<?php
echo $_GET["productID"];
?>
This is my tester, to see if clicking on the link will pass the data from page 1 to displayProduct page.
It successfully passes the variable in the ' URL ' bar but the echo does not display that variable.
Am I missing something?

You missed an echo and have some weird concatenation.
<a href="displayProduct.php?productID=<?php'.$pID.'?>">
should be:
<a href="displayProduct.php?productID=<?php echo $pID; ?>">

<a href="<?php echo 'displayProduct.php?productID=' . $pID; ?>">

The shortest way:
<a href="displayProduct.php?productID=<?php echo $pID ?>">

Related

PHP if database has url echo URL using hyperlinked button

I am trying to see if a file in my database exists, and if it does, show that file as a hyperlinked button. The file is a URL. I am able to get the file to show accordingly, but the button shows even if there is no hyperlink. I have been researching everywhere to find out how I can echo the button only if there is a corresponding file but have had no luck. Just can get it right. Here is what I have and appreciate the help.
<?php if (file_exists($video))?><a class="videobutton" href="<?php echo $video; ?>"></a>
So based on Your Comment that you want to hide the whole button if the file is not found so this is how to do it :
<?php
if (file_exists($video)): ?>
<a class="videobutton" href="<?php echo $video; ?>"></a>
<?php endif; ?>
OR
if (file_exists($video)){ ?>
<a class="videobutton" href="<?php echo $video; ?>"></a>
<?php } ?>
<?php if (file_exists($video)){?>
<a class="videobutton" href="<?php echo $video; ?>"></a>
<?php }
else {
///
} ?>
In my opinion you missed the "{" brackets within the if statement.

Make a php a href link with variable clickable

i have a question.
I have this code to get an profile name as an link.
<a href=<?php echo $userpro->permalink( get_the_author_meta('ID') );
?>><?php echo $user_id=get_the_author_meta('display_name');?></a>
The link isnt clickable. I am a newbie in coding.
So maybe somebody can help me :)
Greetings
Try this:
<a href="<?php echo $userpro->permalink(get_the_author_meta('ID')); ?>">
<?php echo get_the_author_meta('display_name'); ?>
</a>
If it doesnt work... please supply the value and initialisation of $userpro!

Append a GET variable on to a page with another GET variable

I have a profile.php page with a variable uid?=12 and i have a language bar on that is on a separate page called lang.inc.php:
Profile Page:
<div class="langbar">
<?php include 'inc/lang.inc.php'; ?>
</div>
lang.inc.php
<center>
<a class="flag_USA" title="English" href="<?php echo basename($_SERVER['PHP_SELF']); ?>"><img src="css/images/us.png"></a> <span> </span>
<a class="flag_France" title="French" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=fr"><img src="css/images/fr.png"></a> <span> </span>
<a class="flag_dutch" title="Dutch" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=de"><img src="css/images/de.png"></a> <span> </span>
<a class="flag_Italy" title="Italian" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=it"><img src="css/images/it.png"></a> <span> </span>
<a class="flag_Italy" title="" href="<?php echo basename($_SERVER['PHP_SELF']); ?>?lang=es"><img src="css/images/sp.png"></a> <span> </span>
<?php echo $_SERVER['PHP_SELF']; ?>
</center>
As you can see im trying to append the ?lang=fr for example to the end of the profile.php?uid=12 so it looks like this profile.php?uid=12&lang=fr but all it's doing is profile.php?lang=fr.
I'm pretty sure $_SERVER['PHP_SELF'] does not include get variables, just the file path, so you'd have to add the uid to the href yourself.
<?php
$basename = basename($_SERVER['PHP_SELF']); // Lets store the basename
$basename_with_uid = $basename . "?uid=" . $_GET['uid']; // and append the uid from the URL. Make sure to do some validation if $_GET['uid'] exists.
?>
<a class="flag_France" title="French" href="<?php echo $basename_with_uid; ?>&lang=fr"><img src="css/images/fr.png"></a>
REQUEST_URI is probably what you are after:
<a class="flag_France" title="French" href="<?php echo $_SERVER['REQUEST_URI']; ?>&lang=fr"><img src="css/images/fr.png"></a>
If your page was profile.php?uid=12, the output should be:
profile.php?uid=12&lang=fr
Ref: PHP $_SERVER variables
edit You may still need to add basename() around REQUEST_URI, depending on what you are doing

mysql fetch assoc used in url fetching

i have a script in which output localhost/urlfromMysqlDatabase
i need output should be urlfromMysqlDatabase
please give me any suggestions to changes this script
$link = mysql_fetch_assoc(mysql_query("SELECT url FROM admins"));
and in between html body i have a code
<a href="<?php echo $link['url']; ?>" target="_self">
Try this:
<a href="<?php echo #end(explode("/", $link['url'])); ?>" target="_self">
end(explode("/", $link['url'])) will print out urlfromMysqlDatabase (everything after the last slash /).
$link = mysql_fetch_assoc(mysql_query("SELECT url FROM admins"));
$link=end(explode("/",$link['url']));
<a href="<?php echo $link; ?>" target="_self">

If array contains any data

I have these bits here that will display a google map link for me. How can I wrap this in some sort of if statemnt that will check to see if there is ANY data in $event['where']. I don't want the link to display when there is no data.
<a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a>
<?php if(!empty($event)){ ?> <a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a> <?php } ?>
Try this:
<?php echo (!empty($event['where'])) ? $event['where'] : ""; ?>
Well isset() will determine if a variable/object is set and is not null
if(isset($event['where'])){
//...
}
http://php.net/manual/en/function.isset.php
The following will not show the link if $event['where'] is not set, is null, is blank (""), is false or is 0 - I think it is what you want:
<?php
if (!empty($event['where'])) {
?>
<a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a>
<?php
}
?>

Categories