TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-02-2009, 02:28 PM   #1 (permalink)
The Wanderer
 
sandhyagupta's Avatar
 
Join Date: Jun 2009
Posts: 20
Thanks: 4
sandhyagupta is on a distinguished road
Default How to go to a particular page when i click on a particular word?

Hi,

I am in a particular page and this page displays few tables. when i click on a particular work i wanna go to a different page whose url would be something like this :

http://www.konanakunteokkoota.org/applyhereforjob.php?username=$username&post_id=$po stid

Can any one tell me how to do this?
Thanks in advance.
sandhyagupta is offline  
Reply With Quote
Old 07-02-2009, 03:01 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

You will need to be more clear in what you are doing, are you looking for instructions on how to dynamically create links? Where will the data be coming from?
__________________

Village Idiot is offline  
Reply With Quote
Old 07-02-2009, 03:02 PM   #3 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Thread moved to:
Absolute Beginners
codefreek is offline  
Reply With Quote
Old 07-02-2009, 03:02 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
Thread moved to:
Absolute Beginners
Haha, that would explain why it wouldn't let me do it.
__________________

Village Idiot is offline  
Reply With Quote
Old 07-02-2009, 03:06 PM   #5 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

@Village Idiot, sorry hehe ;)

@sandhyagupta, please let us have some more,
info on what your after,
so we can help out :) as Village Idiot, said.
codefreek is offline  
Reply With Quote
Old 07-02-2009, 04:13 PM   #6 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

can't you just create a link and echo it to the page?

PHP Code:
echo '<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&post_id='.$po stid.'">Word</a>'
This is just without knowing what exactly is the situation, or where are you getting the data form, or how do you want/need to output the link. Or maybe you already have some script that we can look at
Like Village Idiot and codefreak said, we need more information to help you out.
tony is offline  
Reply With Quote
Old 07-02-2009, 09:17 PM   #7 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Quote:
Originally Posted by tony View Post

PHP Code:
echo '<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&post_id='.$po stid.'">Word</a>'
So, i might have just posted with a haste, i shall explain my opinion on your quote why, i don't agree on the use of that, 2 reasons, well first, the page load could suffer a big lose if you have a lot of links that are like that, and also safe coding, correct me if i am wrong please do : )

-Cf

Last edited by codefreek : 07-02-2009 at 09:36 PM. Reason: added more explaining
codefreek is offline  
Reply With Quote
Old 07-02-2009, 09:21 PM   #8 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
not a safe way to print out links like that :)
i might add..
No-one said anything about the variables coming from user input. Please explain, while you're happy to add random points to a thread, why the code you quoted is not safe.

sandhyagupta, whether you know it or not, your post was very vague and we really have nothing to go on with regards to understanding your problem and therefore nothing for us to help you with. Please come back and add some more detail to let us know exactly what you're wanting to do.
Salathe is offline  
Reply With Quote
Old 07-02-2009, 09:34 PM   #9 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

I offered my opinion on a post..

//add random points ??, - all thoughts shall be made even if it is not that
useful at that exact time, it is still a community of helping am i not right ?

in my opinion i feel that a page with links like that could, slow it down as well be unsafe, but if i said something that is false, or so on, i am far away from being a php pro, but i do say safe php from the start or even have safe ways to code for example, code that could make a page slow, but please do correct me if i am wrong, no need to (flame up, on something i say)
codefreek is offline  
Reply With Quote
Old 07-02-2009, 10:24 PM   #10 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You make two claims.
  1. Concatenating strings like that will impact on page performance.
    Please clarify why you think this. Have you read some information on this subject which makes the claim, or done some profiling and benchmarking? What more performant alternatives would you use to replace that line of code?
  2. Coding in that manner is somehow unsafe.
    Now, I think that I know where you're coming from on this. The idea is that throwing variables blindly into HTML could, in theory at least, result in the ability to exploit that piece of code (injecting malicious code, for example). However to claim that any code using plain variables concatenated with HTML strings is somehow insecure, I think that's stretching it a bit. Again, what would you do instead of the quoted line of code which would make it much more safe?
Salathe is offline  
Reply With Quote
Old 07-02-2009, 10:42 PM   #11 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Gee. Stop fighting. He was just stating his input, if he's incorrect, just post that in a commonly fasion.

When dealing with variables in links(or in any type of string - like an SQL query), I use sprintf. In this case:

PHP Code:
$link sprintf("http://www.konanakunteokkoota.org/applyhereforjob.php?username='%s'&post_id='%d'",
secure($username),
$post_id);

echo 
'<a href="' $link '">Word</a>'
Where secure is a function where you do the regular string-security checks(mysql_real_escape_string, stripslashes.. etc).
__________________
Tanax is offline  
Reply With Quote
Old 07-02-2009, 10:44 PM   #12 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

on nr 2 on your list/question, i would say at least use sprintf..
codefreek is offline  
Reply With Quote
Old 07-02-2009, 11:42 PM   #13 (permalink)
The Contributor
 
cecilia's Avatar
 
Join Date: May 2009
Location: LA, CA
Posts: 87
Thanks: 0
cecilia is on a distinguished road
Default

I think I would do this just like what tony said, to just directly concatenate it to all of them then echo it in one go, all of the links. After you do the sanitation on both variables that is. I mean im assuming theres like a hundred or something of em, the links.

I have read somewhere that echoing something is slower than directly outputting it outside of php, but as for what Salanthe was asking, I have no idea how much the difference is. I think I said something similar somewhere and was answered that the difference was miniscule or something that it wont matter that much.
cecilia is offline  
Reply With Quote
Old 07-03-2009, 10:13 AM   #14 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Gee. Stop fighting.
Hehe, fighting. There needs to be two sides to fight, all I'm asking for is clarification on the points he raised. If anything, I'm trying to promote healthier discussion here by asking for more than one-line "this is bad" or "this is what you should do" comments. One might see that as fighting, perhaps, but it's not the intention at all.

I still fail to see why the quoted code should be non-performant and insecure which is why I'm pushing for codefreek's own thoughts. It's not about right and wrong (there probably isn't such a clear distinction anyway) but just about making claims without putting them in context. Why do you think the code would be slowed down, what would you suggest instead? Why do you think the code is insecure, what would you suggest instead?
Salathe is offline  
Reply With Quote
Old 07-03-2009, 11:14 AM   #15 (permalink)
The Wanderer
 
sandhyagupta's Avatar
 
Join Date: Jun 2009
Posts: 20
Thanks: 4
sandhyagupta is on a distinguished road
Default

I will want to click on any of the postions displayed in my table and then it has to direct me to that page depending on the postion. Hope i am clear this time.
sandhyagupta is offline  
Reply With Quote
Old 07-03-2009, 11:31 AM   #16 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
Hehe, fighting. There needs to be two sides to fight, all I'm asking for is clarification on the points he raised. If anything, I'm trying to promote healthier discussion here by asking for more than one-line "this is bad" or "this is what you should do" comments. One might see that as fighting, perhaps, but it's not the intention at all.

I still fail to see why the quoted code should be non-performant and insecure which is why I'm pushing for codefreek's own thoughts. It's not about right and wrong (there probably isn't such a clear distinction anyway) but just about making claims without putting them in context. Why do you think the code would be slowed down, what would you suggest instead? Why do you think the code is insecure, what would you suggest instead?
Ah, I see. Well there are 2 sides. You - Codefreek.
But whatever.

I think he should use sprintf anyways, as I said

Quote:
Originally Posted by sandhyagupta View Post
I will want to click on any of the postions displayed in my table and then it has to direct me to that page depending on the postion. Hope i am clear this time.
Just echo a link with the positions' ID to a page where it checks which ID is being sent through, and process the data there.
__________________
Tanax is offline  
Reply With Quote
Old 07-03-2009, 01:57 PM   #17 (permalink)
The Wanderer
 
sandhyagupta's Avatar
 
Join Date: Jun 2009
Posts: 20
Thanks: 4
sandhyagupta is on a distinguished road
Default

Thanks everybody for the reply.. my code is working fine as i wanted. But have a small error again. when i click n the first postion it is not taking the jobid. but when i click on the second one then it is taking the first job id and so on.
What exactly is the error.

My code goes this way
PHP Code:
<?php
$nickname 
$_POST['company_nickname'];
include 
'connect_to_databaseemployer.php';

//To fetch all the sub-employer usernames from sub_employer if the company nickname matches
$sql_stmt "SELECT * FROM database name WHERE company_nick='$nickname'";
$result  mysql_query($sql_stmt$conn) or die(mysql_error());
while (
$row mysql_fetch_assoc($result))
{
      
$username =  $row["username"];
      
}

//To check whether the user has any posting.If yes,display the postings sorted by date of posting
$sql_stmt1 "SELECT * FROM database nameWHERE posted_by like '%$nickname%' ORDER BY job_posted_on DESC";
$result1  mysql_query($sql_stmt1$conn) or die(mysql_error());
echo 
"<table border='1' CELLPADDING=5 STYLE='font-size:13px'>";
echo 
"<tr> <th><H3>Posted by</h3></th> <th><H3>Position</H3></th> <th><H3>Job Level</H3></th><th><H3>Posted on</h3></th></tr>";

while (
$row1 mysql_fetch_assoc($result1))
{
      echo 
"<tr><td>";
      echo 
$row1["posted_by"];
      echo 
"</td><td>";
      echo 
'<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&jobid='.$postid.'">'.$row1["position"].'</a>';  
      echo 
"</td><td>";
      echo 
$row1["job_level"];
      echo 
"</td><td>";
      echo 
$row1["job_posted_on"];
      echo 
"</td></tr>";
      
$postid $row1["post_id"];
      echo 
"$postid";
}
echo 
"</table>";

?>
sandhyagupta is offline  
Reply With Quote
Old 07-03-2009, 02:10 PM   #18 (permalink)
The Acquainted
 
Hightower's Avatar
 
Join Date: May 2009
Location: Durham, UK
Posts: 134
Thanks: 9
Hightower is on a distinguished road
Default

Just a guess as I haven't looked properly but maybe you have to increment your job id i.e.:

PHP Code:
echo "</td><td>";

$postid += 1;

echo 
'<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&jobid='.$postid.'">'.$row1["position"].'</a>';  
echo 
"</td><td>"
__________________
Hightower's Softpolio
Send a message via MSN to Hightower
Hightower is offline  
Reply With Quote
Old 07-03-2009, 02:43 PM   #19 (permalink)
The Wanderer
 
sandhyagupta's Avatar
 
Join Date: Jun 2009
Posts: 20
Thanks: 4
sandhyagupta is on a distinguished road
Default

Thanks every one. there was a small mistake in the while loop.. now its working fine..
PHP Code:
while ($row1 mysql_fetch_assoc($result1))
{
      echo 
"<tr><td>";
      echo 
$row1["posted_by"];
      echo 
"</td><td>";
      
$postid $row1["post_id"];
      echo 
'<a href="http://www.konanakunteokkoota.org/applyhereforjob.php?username='.$username.'&jobid='.$postid.'">'.$row1["position"].'</a>';  
      echo 
"</td><td>";
      echo 
$row1["job_level"];
      echo 
"</td><td>";
      echo 
$row1["job_posted_on"];
      echo 
"</td></tr>";

I had to just move the $postid before using the url. now its working fine.
sandhyagupta is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Execute a script and call that file in an HTML page j4v1 General 2 05-22-2008 01:41 PM
Page Load Count Wildhoney Script Giveaway 1 03-25-2008 04:48 AM
vB Hack - Making a Home Page Karl General 1 12-19-2007 04:08 PM
Extracting page titles and placing into dropdown box. Dorza General 6 10-29-2007 11:01 PM


All times are GMT. The time now is 06:33 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design