Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2009, 10:00 AM
Saphira Saphira is offline
Member
 
Join Date: Jan 2009
Posts: 89
Credits: 5,858
Saphira
Default PHP in a link?

Okay, I've created a new user profile page for the script, but I'm having some issues linking it up. How can I create a link, where half of it depends on the users ID? For example, www.yourdomain.com/viewprofile.php?id=1 will direct you to the users page who has the user ID of 1. But I have no idea how to set this up, so that if a user clicks a profile link, it will echo their ID from the database into the ?id=* bit.

I hope this makes sense, because it's a lot harder to explain than I thought it'd be. Heh.

Cheers!
Reply With Quote
  #2  
Old 01-28-2009, 04:42 PM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 11,269
BMR777 is on a distinguished road
Default RE: PHP in a link?

I am assuming you have another application that you are trying to integrate into my script somehow?

If you know the username of a user you can easily find the ID and vise versa, assuming both scripts are running on a shared database. So, say you know the username of a user and you want to get their ID number, which is what I assume you want to do.

You would do:

PHP Code:
$username "Username Goes Here";
$username mysql_real_escape_string($username); //Prevent against SQL injection

//SQL query to get the ID number based on a username

$query "SELECT * FROM users WHERE username = '".$username."'";
$result mysql_query($query);
$num mysql_numrows($result);

//Loop out code
$i=0;
while (
$i 1) {

$uid=@mysql_result($result,$i,"uid");


$i++;
}

//Now we have the user's ID number, so we make a link...
echo "<a href='viewprofile.php?id=".$uid."'>Click Here</a>"
I hope this helps. If this isn't what you need please give me more info / examples of what you want to do and I'll try and help as best I can.

Brandon
Reply With Quote
  #3  
Old 01-29-2009, 09:56 AM
Saphira Saphira is offline
Member
 
Join Date: Jan 2009
Posts: 89
Credits: 5,858
Saphira
Default RE: PHP in a link?

Not quite lol.

Here is the page that I have created:

PHP Code:
<?php

// Easy Adoptables Script by Brandon Rusnak
// Get our includes out of the way

include("inc/functions.php");
include(
"inc/levels.php");
include(
"inc/config.php");
include(
"inc/settings.php");
include(
"inc/nbbc.php");  // BBCODE Parser
$bbcode = new BBCode;

// Connect to our database

$conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql database!');
mysql_select_db($dbname);


//Set up our login info...
$username "";
$password "";

//Check for cookie

if (isset($_COOKIE['adoptu']) and isset($_COOKIE['adoptp'])){

$username $_COOKIE['adoptu'];
$password $_COOKIE['adoptp'];

$username preg_replace("/[^a-zA-Z0-9\\040.]/"""$username);
$password preg_replace("/[^a-zA-Z0-9s]/"""$password);

//Run login operation
$query "SELECT * FROM users WHERE username = '$username'";
$result mysql_query($query);
$num mysql_numrows($result);

//Loop out code
$i=0;
while (
$i 1) {

$luser=@mysql_result($result,$i,"username");
$lpass=@mysql_result($result,$i,"password");

$i++;
}

    if(
$username == $luser and $password == $lpass){
        
$isloggedin "yes";
    }
    else{
    if (isset(
$_COOKIE['adoptu'])){
    
$past time() - 10
    
setcookie("adoptu",$username,$past);
    }

    if (isset(
$_COOKIE['adoptp'])){
    
$past time() - 10
    
setcookie("adoptp",$password,$past);
    }
    
$isloggedin "no";
    }

}
else
{
//User is not logged in
$isloggedin "no";



//Begin our content for the page
$id $_GET["id"];
$id preg_replace("/[^a-zA-Z0-9s]/"""$id);


//Begin the level up procedure

if($id != ""){
//Adoptable ID is not empty, continue...
    //Check that the adoptable does in fact exist...
    
$query "SELECT * FROM users WHERE uid = '$id'";
    
$result = @mysql_query($query);
    
$num = @mysql_numrows($result);

    
//Loop out code
    
$i=0;
    while (
$i 1) {

    
$uname=@mysql_result($result,$i,"username");
    
$imageurl=@mysql_result($result,$i,"imageurl");
    
$realname=@mysql_result($result,$i,"realname");
        
$email=@mysql_result($result,$i,"email");
        
$location=@mysql_result($result,$i,"location");
        
$aim=@mysql_result($result,$i,"aim");
        
$msn=@mysql_result($result,$i,"msn");
        
$birthday=@mysql_result($result,$i,"birthday");



    
$i++;
    }
    if(
$uname != ""){
    
$article_title "Profile of ".$uname.".";
    
$article_date date('Y-m-d');
    
$article_content "<img src='".$imageurl."' border='0'><br><br>
    <b>Real Name: </b>"
.$realname."<br>
        <b>Email: </b>"
.$email."<br>
    <b>Location: </b>"
.$location."<br>
    <b>AIM: </b> "
.$aim."<br>
        <b>MSN: </b> "
.$msn."<br>
        <b>Birthday: </b> "
.$birthday."<br>

    Like the sound of "
.$username."?  <b><a href='addfriend.php?id=".$id."'>Click here to add them to your friend's list!</a></b>";
    }
    else {
    
$article_title "Invalid Adoptable ID";
    
$article_date date('Y-m-d');
    
$article_content "The adoptable ID specified does not exist in our system.  If you would like your own adoptable you can
    <a href='adopt.php'>get one free here</a>."
;
    }


}
else{
$article_title "No Adoptable Specified";
$article_date date('Y-m-d');
$article_content "You did not specify an adoptable ID to show.  If you would like your own adoptable you can
<a href='adopt.php'>get one free here</a>."
;
    

}



// Define our Template File

$file $current_theme;

$article_title stripslashes($article_title);
$article_content stripslashes($article_content);



// Should we show the extra pages in the nav bar?

$link1 "";
if(
$show_extra_page1 == "yes"){
$link1 "<li><a href='$extra_page1_link'>$extra_page1_name<span class='tab-l'></span><span class='tab-r'></span></a></li>"
}

$link2 "";
if(
$show_extra_page2 == "yes"){
$link2 "<li><a href='$extra_page2_link'>$extra_page2_name<span class='tab-l'></span><span class='tab-r'></span></a></li>"
}

// Do the template changes and echo the ready template

$template file_get_contents($file);
$template replace(':SITETITLE:',$site_title,$template);
$template replace(':SITENAME:',$site_name,$template);
$template replace(':ARTICLETITLE:',$article_title,$template);
$template replace(':ARTICLEDATE:',$article_date,$template);
$template replace(':ARTICLECONTENT:',$article_content,$template);
$template replace(':LINK1:',$link1,$template);
$template replace(':LINK2:',$link2,$template);
$template replace(':LINK3:',$link3,$template);

//Get the featured adoptable...
$featured getfeatured();
$template replace(':FEATURED:',$featured,$template);

//Ad Management
$header = @file_get_contents("ads/header.txt");
$footer = @file_get_contents("ads/footer.txt");
$tower = @file_get_contents("ads/tower.txt");

$header stripslashes($header);
$footer stripslashes($footer);
$tower stripslashes($tower);

$template replace(':HEADERAD:',$header,$template);
$template replace(':FOOTERAD:',$footer,$template);
$template replace(':TOWERAD:',$tower,$template);


//Is the user logged in?
//$isloggedin = "no";
if ($isloggedin == "yes"){
$template replace(':WELCOMEORREGISTER:','<u>Welcome Back:</u>',$template);
$template replace(':LOGINORACCT:''Welcome back '.$username.'.  <br><br><a href="logout.php">Log Out</a>' ,$template);
}
else{

//User is not logged in
$template replace(':WELCOMEORREGISTER:','<u>Member Login:</u>',$template);
$loginform "<form name='form1' method='post' action='login.php'>
  <p>Username: 
    <input name='username' type='text' id='username'>
</p>
  <p>Password: 
    <input name='password' type='password' id='password'>
</p>
  <p>
    <input type='submit' name='Submit' value='Submit'>
  </p>
  <p>Don't have an account?<br>
  <a href='register.php'>Register Free</a>  </p>
</form>
"
;
$template replace(':LOGINORACCT:'$loginform ,$template);
}

echo 
$template;
?>
As you can tell, I've just modified one of your pages (well, started to mod), to create a more detailed profile page. The only thing that I'm having trouble with is linking to this page. I want to replace the current account page with this one. So the "My Account" link, will link to this page. I'm just not sure how to go about putting php in a link to add the users ID onto the end of the link.

I'm definitely donating to help support this project when I get paid a week tomorrow. Thanks Brandon!
Reply With Quote
  #4  
Old 01-29-2009, 02:34 PM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 11,269
BMR777 is on a distinguished road
Default RE: PHP in a link?

Well, I'm a bit confused now since you seem to be saying you want to replace the My Account page with the page above. The My Account page is for editing user-specific settings whereas the page you have here appears to be used to add a user to the friends list of another user.

I think I know what you want to do though and I think I have a better idea of what you are saying. I think what you are saying is when you have an adoptable shown somewhere on the site, how can you have the owner of that adoptable linked in to this page to add another user as a friend? Right?

Take this example: Say we have a page like this one where you have the adoptable and the owner's name. Now I am assuming that you want to link the owner's name or ID number to the page you have created, right?

Well, in the file show.php we would find:

PHP Code:
if($name != ""){
    
$article_title "Profile of ".$name.".";
    
$article_date date('Y-m-d');
    
$article_content "<img src='".$imageurl."' border='0'><br><br>
    <b>"
.$name."'s Level: </b>".$currentlevel."<br>
    <b>Total Clicks: </b>"
.$totalclicks."<br>
    <b>"
.$name." is owned by:</b> ".$owner."<br><br>
    Like "
.$name."?  <b><a href='levelup.php?id=".$id."'>Click Here to level them up!</a></b>";
    } 
That code outputs the user's adoptable so anyone can view it. Now, for the line:

PHP Code:
<b>".$name." is owned by:</b".$owner."<br><br
Change To:

PHP Code:
<b>".$name." is owned by:</b> <a href='yourpage.php?id=".$owner."'>".$owner."</a><br><br
That makes a clickable link to the page you created. When a user clicks on the user's name then it will show their profile page that you created, well almost...

In your file, change:

PHP Code:
 $query "SELECT * FROM users WHERE uid = '$id'"
to

PHP Code:
 $query "SELECT * FROM users WHERE username = '$id'"
You could add an extra step in the show.php to convert the username to an ID number, but I don't think this is necessary.

Really, how you link a user's username to your show profile page depends on the file you want to link from. I hope this has helped some and feel free to let me know if you have any questions.

Brandon
Reply With Quote
  #5  
Old 01-30-2009, 12:36 PM
Saphira Saphira is offline
Member
 
Join Date: Jan 2009
Posts: 89
Credits: 5,858
Saphira
Default RE: PHP in a link?

Hmm, I'm not trying to change anything in my file. I want to change the <a href=account.php> My Account </a> link in the template file to <a href=viewprofile.php?id=[logged in user's ID]> My Account </a>. I tried using <a href=viewprofile.php?id=".$id."> My Account <a> but that just linked to viewprofile.php?id=".$id." instead of replacing the ".$id." with the logged in user's ID.

Does this make any more sense?
Reply With Quote
  #6  
Old 01-30-2009, 01:44 PM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 11,269
BMR777 is on a distinguished road
Default RE: PHP in a link?

Ok, try this:

In the template file, just go ahead and remove the My Account link all together.

Then, in each php file find:

PHP Code:
$link2 "";
if(
$show_extra_page2 == "yes"){
$link2 "<li><a href='$extra_page2_link'>$extra_page2_name<span class='tab-l'></span><span class='tab-r'></span></a></li>"

Add Below:

PHP Code:
if($username != ""){

$link3 "<li><a href='viewprofile.php?id=".$username."'>My Account<span class='tab-l'></span><span class='tab-r'></span></a></li>"

That should make it where if the user is logged in a link will appear at the top of the page that says My Account. When they click on it they will be taken to viewprofile.php?id=USERNAME_HERE.

Try this edit on one file and see if it works and if so then apply it to all the PHP files. :)

Brandon
Reply With Quote
  #7  
Old 01-30-2009, 11:24 PM
Saphira Saphira is offline
Member
 
Join Date: Jan 2009
Posts: 89
Credits: 5,858
Saphira
Default RE: PHP in a link?

Okay, that works to perfection. But how would I go about making it display the uid instead of the username? Replacing it username with id doesn't display the number. It just displays ?id=
Reply With Quote
  #8  
Old 01-31-2009, 08:54 AM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 11,269
BMR777 is on a distinguished road
Default RE: PHP in a link?

If you want to use the ID number, you have to use this code before your link to convert the username to its id number:

PHP Code:
$query "SELECT * FROM users WHERE username = '".$username."'";
$result mysql_query($query);
$num mysql_numrows($result);

//Loop out code
$i=0;
while (
$i 1) {

$id=@mysql_result($result,$i,"uid");


$i++;

Brandon
Reply With Quote
  #9  
Old 01-31-2009, 11:23 AM
Saphira Saphira is offline
Member
 
Join Date: Jan 2009
Posts: 89
Credits: 5,858
Saphira
Default RE: PHP in a link?

So, the complete code I need to add after the second link, is:

PHP Code:
$query "SELECT * FROM users WHERE username = '".$username."'";
$result mysql_query($query);
$num mysql_numrows($result);

//Loop out code
$i=0;
while (
$i 1) {

$id=@mysql_result($result,$i,"uid");

if(
$username != ""){

$link3 "<li><a href='viewprofile.php?id=".$username."'>My Account<span class='tab-l'></span><span class='tab-r'></span></a></li>"

Cheers!
Reply With Quote
  #10  
Old 01-31-2009, 11:30 AM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 11,269
BMR777 is on a distinguished road
Default RE: PHP in a link?

Missing a few things...

PHP Code:
$query "SELECT * FROM users WHERE username = '".$username."'";
$result mysql_query($query);
$num mysql_numrows($result);
//Loop out code
$i=0;
while (
$i 1) {

$id=@mysql_result($result,$i,"uid");

$i++;
}

if(
$username != ""){

$link3 "<li><a href='viewprofile.php?id=".$username."'>My Account<span class='tab-l'></span><span class='tab-r'></span></a></li>"

The way you had was an infinite loop that would never complete. :)
Reply With Quote
Reply


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Link Dots voni Questions and Supports 6 05-13-2014 10:20 AM
Link MaximumRide Questions and Supports 6 04-23-2012 04:52 PM
Getting my forums to link as a sub? Aasixx Questions and Supports 4 04-20-2012 04:20 AM
how change this link ? :( kratosvr Questions and Supports 5 08-24-2011 09:09 AM
Forums Link Ashje Questions and Supports 2 01-24-2009 12:28 AM


All times are GMT -5. The time now is 04:28 PM.

Currently Active Users: 724 (0 members and 724 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636