Give href to a php variable - php

I want to give href link to the variable below;
echo "<td>" . $row['userid'] . "</td>";
So that admin can click on that ID and in the other page admin can see all details about the user, using this id.
I tried;
echo "<td>" . $row['userid'] . "</td>";
and
echo "<td>" . $row['userid'] . "</td>";
But they didn't work. Thanks in advance.
edit:
Thanks to #Gautam the answer I'm looking for is below;
echo "<td><a href='http://www.google.com'>". $row['expiry'] . "</a></td>";

use this
echo "<td>Click Here</td>";
or else
?>
<td>Click Here</td>

Please use single quotas for your link. If you are using double quotas you will close your echo instead of opening quotas within other quotas:
echo "<td><a href='http://www.google.com'>" . $row['expiry'] . "</a></td>";
Otherwise you also could use \ in order to escape the double quotas:
echo "<td>" . $row['expiry'] . "</td>";

You are gettting error because of quotes. Change the quotes for href to single quotes like below and should work fine.
echo "<td><a href='http://www.google.com'>". $row['expiry'] . "</a></td>";

Related

How to make inside html table in php echo a normal contest

Well what i want to what is to add here
echo "<td>" . $row["seller"] . "</td>";
I want to make it like this
echo "<td>" Seller : . $row["seller"] . "</td>";
But this gives me an error , how to correctly write it
Like the resultat be like
Seller : and the value of the $row
You can just do it like this:
echo "<td> Seller: ". $row["seller"] . "</td>";
strings go inside "" in PHP.
Or you can do it like this:
echo '<td> Seller: '. $row["seller"] . '</td>';
'' will transform anything inside it to their HTML equivalent since "" treats everything inside it as a string.

Sending MySQL data to page through link in a table

We are currently working on a game shop website and have hit a roadblock regarding the purchase link.
The link displays within a mysql table and each link sends the user to the same page.
This is necessary as we will be adding new games to the database and want to do using only a mysql command to make the site as efficient as possible.
This is the code of the table (ignore the fact that the purchase link displays the 'gameCodes'.
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['gameName'] . "</td>";
echo "<td>" . $row['pointsValue'] . "</td>";
echo "<td>" . ''. $row['gameCodes'] .'' . "</td>";
echo "</tr>";
}
echo "</table>";
What I am wanting to do is send the game code of the game that corresponds with the row the link is on to the Purchase.php page to then process the purchase.
Any help is appreciated greatly.
my answer deals with not only passing variables from url to your page....but passing it in clean way
First, make sure that url URL properly encode using "PHP urlencode"
echo "<td>" .
'<a href="Purchase.php?gameCodes='.urlencode($row['gameCodes']) .'">'.
$row['gameCodes'] .
'</a>' .
"</td>";
Then to fetch the data strip_tags from the url variable if any:
echo (strip_tags($_GET['item']));
why is this needed??
Since you are fetching the values from URL, assume i manually change the url to :
Purchase.php?gameCodes=<script>alert("hello")</script>
then without proper handling, gameCodes variable value will be fetched and it would alert "hello" on the page
Have you thought about sending it through the URL like follow:
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['gameName'] . "</td>";
echo "<td>" . $row['pointsValue'] . "</td>";
echo "<td>" . ''. $row['gameCodes'] .'' . "</td>";
echo "</tr>";
}
echo "</table>";
and then process to the purchase using the code sent in the URL
let me know if it corresponds to what you need.
I think you can put the gameCodes id directly in the link
echo "<td>" .
'<a href="Purchase.php?gameCodes='. $row['gameCodes'] .'">'.
$row['gameCodes'] .
'</a>' .
"</td>";
Now you can process the code from the purchase page and retrieve it with $_GET
$_GET['gameCodes'];

passing a link title to the next page

I'm trying to make automatically generated pages for users based on the username.
Basically I'm creating a table in HTML which displays all the users currently registered. The names are hyperlinks which redirect to a page in which I will post a welcome message.
The problem is that I don't know how to pass the name of the user I click on to the next page.
<table border='1'>
<tr>
<th>Username</th>
<th>Email</th>
</tr>
<?php
while($currentRow = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $currentRow['name'] . "</td>";
echo "<td>" . $currentRow['email'] . "</td>";
echo "</tr>";
}
?>
As you can see, I tried using get, but it won't work, I think it's because it doesn't know what I'm clicking on. The point is that I want the page with the welcome message say something like "welcome, $username". Any ideas?
You are closing the string with single quotes "'" that is why $_GET does not work. Replace profile.php?name='" with profile.php?name=" and also remove the single quote on the other end.
You have need remove single quote after ?name= and add it to before character >
Use
echo "<td><a href='/templates/profile.php?name=". $currentRow['name'] ."'>" .
$currentRow['name'] . "</a></td>";
Instead of
echo "<td><a href='/templates/profile.php?name='". $currentRow['name'] .">" .
$currentRow['name'] . "</a></td>";
try this in profile.php
Welcome <?php echo $_GET['name'];?>
In your profile.php
echo $_GET['name'];
echo "<td><a href='/templates/profile.php?name=". $currentRow['name'] ."'>" . $currentRow['name'] . "</a></td>";
close the single code after name value you are sending in a tag..
thats it.

id not going through the url

my id is not going through the url. my code is as follows
<?php
include 'library/connect.php';
$result = mysql_query("SELECT * FROM meetings ");
echo "<table border='1'><tr><th>Title</th><th>Chairman</th><th>Secretary</th><th>Terms of Reference</th><th>Named membership</th><th>Occurences</th><th>Book Room</th></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['title']. "</td>";
echo "<td>" . $row['chairman']. "</td>";
echo "<td>" . $row['secretary']. "</td>";
echo "<td>" . $row['termsOfReference']. "</td>";
echo "<td>" . $row['named_membership']. "</td>";
echo "<td>" . $row['occurences']. "</td>";
?>
<td><font color="#CC3300">Book: room/date/time</font></td>
<?php
}
echo "</tr>";
echo "</table>";
include 'library/closedb.php';
?>
have you got any idea of what the problem can be?
where is $meeting_id set? seems to me like it should be $row['meeting_id'].
Where $meeting_id is defined?
It seems like you did a select but forgot to retrieve the meeting id.
Try to change the link to:
<a href ="secretary_booksRoom.php?meeting_id=<?php echo $row['meeting_id']; ?>">
In case you have column named meeting_id in your table of course.
<tr> tag need to be closed in the while loop
You need to define the $meeting_id variable before adding it to the URL, otherwise your link will simply be "secretary_booksRoom.php?meeting_id=". I am going to assume that your meetings table has an id column as a primary key. In your while loop, try declaring "$meetind_id = $row['your meeting id column']". This should get the meeting id and pass it to the URL.
Hope this helps.

PHP How to pass variables through a link to the next php file

echo "<td>" .
"<a href='approve_mem.php?id=$row['member_id']'>Approve</a>" . " " .
'Disapprove' .
"</td>";
This is my code but the value of id does not get passed instead it gets passed like id=$row['member_id'] as it is, and when I echoed the id variable it got printed like $row['member_id']
Rather than building HTML strings in PHP, I recommend you only switch to the PHP context when required, eg
<td>
Approve
Disapprove
</td>
Try this:
echo "<td>" .
"<a href='approve_mem.php?id=".$row['member_id']."'>Approve</a>" . " " .
'Disapprove' ."</td>";
You need to change it to:-
echo "<td>" .
"<a href='approve_mem.php?id={$row['member_id']}'>Approve</a>" . " " .
"<a href='disapprove_mem.php?id={$row['member_id']}'>Disapprove</a>" .
"</td>";
Notice the use of curly braces and the change of quotes used in the second line. Also you hadn't quoted member_id in your second use of $row['member_id']
Also take note of Dagon's comment above.
I am guessing this is part of a database query. You have to seperate the data from the string in this instance. This can be written two ways:
<td>
Disapprove
</td>
------------- OR -------------
echo "<td><a href='approve_mem.php?id=".$row['member_id']."'>Approve</a> <a href='disapprove_mem.php?id=".$row['member_id']."'>Disapprove</a></td>";
change that to this:
echo "<td>Approve
Disapprove</td>";
or
<td>
<a href='approve_mem.php?id=<?=$row['member_id']?>'>Approve</a>
<a href='disapprove_mem.php?id=<?=$row['member_id']?>'>Disapprove</a>
</td>

Categories