I am using the following code to display a hyperlink inside a table:
echo "<td><a href=http://www.smstoneta.com/show.php?opcode=TCP Y".">".
$row['num_y']."</a></td>";
The hyperlink is displayed successfully but when I click on the hyperlink, the URL is
www.smstoneta.com/show.php?opcode=TCP
instead of
www.smstoneta.com/show.php?opcode=TCP Y
Why am I not getting the full URL?
Use urlencode()
$opCode = urlencode('TCP Y');
echo "<td>".$row['num_y']."</td>";
You need URL Encode spaces to make them working in links.
Here is manual for PHP function urlencode
$safe_url = urlencode('http://www.smstoneta.com/show.php?opcode=TCP Y');
echo "<td>" .$row['num_y']. "</td>";
BTW, more readable (no concatenation needed) version to echo such strings is:
echo "<td><a href='{$safe_url}'>{$row['num_y']}</a></td>";
Related
i am trying to create a dynamic link. $path="uploads/" and $fileName="Data Communication and Networking.pdf" which is retrieved from database. But the link gets created with href="upload/Data" ignoring the " Communication and Networking.pdf" part. How to add $fileName with spaces between the content.
$message=$row["message"];
$fileName=$row["filename"];
$date=$row["date"];
echo "<tr>";
echo "<td>".$Serial."</td>";
echo "<td>".$message."</td>";
echo "<td>Download</td>";
echo "<td>".$date."</td>";
echo "</tr>";
$Serial++;;
href value must consist in quotes. Place single quotes around your value.change your href as below:
echo "<td><a href='".$path.$fileName."'>Download</a></td>";
You can replace any space with %20
$CompletePath = str_replace(" ", "%20", $path . $fileName);
echo "<td>Download</td>";
//uploads/Data%20Communication%20and%20Networking.pdf is a valid URL
$path="/path";
$filename="/file with space.name";
echo "<td>Download</td>";
Will output:
`<td><a href=/path/file with space.name>Download</a></td>`
So you need to put the path between the quotes like this:
$path="/path";
$filename="/file with space.name";
echo "<td><a href='".$path.$fileName."'>Download</a></td>";
I would like to create a link within a while loop where the anchor link is a record from the query and the href passes a variable from the same query to another page so I only have to create one page that displays information based on the passed variable.
echo "<td>";
echo ''$row['result']''';
echo "</td></tr>";
This link kills my page and return an error.
echo "<td>";
echo ''.$row['result'].'';
echo "</td></tr>";
Should fix your code your quotes are not closed right
Your href string concatenation is incorrect.
It seems like you tried closing your strings and concatenating them halfway through and then stopped. Even with Stack Overflow you can see the string errors.
This is how your href echo should look:
echo '<a href="stats_game.php?idGame=' .$row['idGame'] . '>' . $row['result'] . '</a>';
It works fine for me
echo "<td><a href='stats_game.php?idGame=".$row['idGame']."'>".$row['result']."</a></td>";
I am trying to create the necessary url from this code however it is working and I am struggling to find out why.
$linkere = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linkere); ?>">'
Currently this code is producing the url: me.php?message= . But, I would like it to create the url: me.php?message=hello for example.
Thanks for helping!
You are passing $linkere to rawurlencode(). The variable is actually named $linker.
$linker = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linker); ?>">'
You have alot of syntax problems here.
first, you need to use Concatenation message='.rawurlencode($linker).'"
second your variable do not exist, it should be $linker.
Second close the tag and insert the text, in this case i used Test.
$linker = $row['message'];
echo 'Test';
Can you try this,
$linker = $row['message'];
echo 'YOUR LINK TEXT HERE';
You don't need the <? ?> and echo in your echo, it should just be:
$linkere = $row['message'];
echo 'Test';
Otherwise you are turning php on and off again to echo something within an already open instance of php in which you are already echoing.
I have a edit URL on my webpage, and want to redirect to the same page and execute the code.
Example: test.php: edit url clicked -> test.php.
code test.php:
while ($row = mysql_fetch_array($query)){
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td><a href='test.php&id=".$row['id']."'>Edit</a></td>";
echo "</tr>";
}
Now I have the following code also in test.php
if (isset($_GET['id'])){
echo "Test";
}
Output:
http://prntscr.com/2cauwi
Why does it not $_GET the ID and echo test?
The question mark is used as the separator. That's what separates your query string from the rest of the URL. In this case, the query string isn't separated properly (because you're using & as the separator) and it tries to access an incorrect page, causing a 404 error. The URL should be the following instead:
example.com/includes/test/test.php?id=14
^
You use & when you have multiple query parameters. For example:
example.com/includes/test/test.php?id=14&name=Foo
echo "<td><a href='test.php?id=".$row['id']."'>Edit</a></td>";
change this line
echo "<td><a href='test.php&id=".$row['id']."'>Edit</a></td>"
to
echo "<td><a href='test.php?id=".$row['id']."'>Edit</a></td>"
Note the ? instead of the & the & is only used for subsequent parameters.
I am creating a hyperlink in foreach loop. It is working fine. When I am passing $id in URL parameter then it is not working. my link is showing http://****/test/index.php/test/view?id=**. i don't what i am doing wrong here.
foreach($list as $item)
{
$rs[]=$item['uname'];
$id=$item['uid'];
//var_dump($id); here it's printing $id value...
echo '<b> '.$item['uname'].'<br/>';
}
I want to pass $id value with hyperlink. Please suggest me.
It's of course getting printed -- your browser is just not displaying it to you since it's not being correctly parsed as HTML due to the extra " around the $id variable.
Set your header as follows:
header('Content-Type: text/plain');
and you'll see that it returns something like:
<b> FOOBAR<br/>
^ ? ^
As you can see, the issue is the extra double-quote before 55.
Change your code to:
echo '<b> <a href="/test/index.php/test/view?id=' . $id .'">'.
$item['uname'] . '</a><br/>';
Alternatively, you could also use double-quotes and enclose your variables inside {}, like so:
echo "<b> <a href=\"/test/index.php/test/view?id=$id\">{$item['uname']}
</a><br/>";
I'd use sprintf as it's cleaner.
echo sprintf('<b> %s<br/>', $id, $item['uname']);
You have another ".
Change this:
echo '<b> '.$item['uname'].'<br/>';
To this:
echo '<b> '.$item['uname'].'<br/>';
Try this:
echo "<b><a href='/test/index.php/test/view?id=$id'>$item</a></b><br/>";
This works!
And is the easiest and cleanest option. Inside of the double escaping, the simple is used for the html and through the double escaping all variables are written inside :) . Very simple.