Jump to content

Help with URL


ChrisMartino

Recommended Posts

OK so i want to make it so when somebody types in the url bar profile.php?member=1234

 

How would i get that there?, (The 1234) i need to be able to get that in a variable somehow so i can do a if statement with it, Because i need to do

 

$member = "member";

 

if($member == $TheVariableID)

{

      // DO something here

}

 

 

Dose anyone know i really need to know :/

Link to comment
Share on other sites

It didn't work :/

 

this is my code:

 

		if ($member == $memberID) {
		?>
			<center>
				<img src="<?=$_SESSION['AccountPic']?>" width="130" height="130">
				<br />
				<a href="profile.php?change=pic">[Change Picture]</a>
				</center>
				<br />

				<?php
				echo $memberID;
				echo "<b>Username:</b> $User";
				?>
				<br />
				<?php
				echo "<b>IP Address:</b> $AccountIP";
				?>
				<br />
				<?php
				echo "<b>Email Address:</b> $Email <a href=\"profile.php?change=email\">[Change]</a>";
				?>
				<br />
				<?php
				echo "<b>Account Type:</b> $AccTyp";
				?>
				<br />

		<?php
				if($AccountQurey == $Administrator)
				{
					echo "<b>Administrator:</b> Yes";
				}
				else
				{
					echo "<b>Administrator:</b> No";
				}


		}

 

 

"echo $memberID;" is supposed to echo the number you put in the address bar eg profile.php?member=123" that should of echoed 123 but it didn't

Link to comment
Share on other sites

If that's the case, then nothing will be displayed as $memeber can not match $memberID, This is what this if statement is saying

if ($member == $memberID) {

 

I dont understand how $member can be the same as $memberID. I need to see more code so I can understand whats going on.

Link to comment
Share on other sites

If you only want to show the profile for the id specified in the url, eg 123 then this is how I'd do it

<?php

// connect to mysql here etc

// check that memberID is declared in the url, eg profile.php?member=123
if(isset($_GET['member']) && is_numeric($_GET['member']))
{
    // get the member id
    $memberID = (int) $_GET['member'];

    // Select only the row that matches memberID being requested, eg 123
    $query = "SELECT * FROM members_table WHERE memberID = '$memberID'";
    $result = mysql_query($query);

    // check that the query returned one row, meaning a match was found
    if(mysql_num_rows($result) == 1)
    {
        // grab the results from the query
        $row = mysql_fetch_assoc($result);

        // display profile here
       printf('<pre>%s</pre>', print_r($row, true));
    }
    // a match was not found. Display an error instead
    else
    {
        echo '<p style="color:red">Member does not exists</p>';
    }
}
// Either the member id was not declared or it was invalid. Display an error
else
{
    echo 'Invalid member id specified';
}

?>

Link to comment
Share on other sites

Ok, So i did what you said tried it and it worked :D, One problem though, I tried to implement it into my profile.php and it didnt work, Nothing happens at profile.php?member

 

This is the full page:

 

<?php include "Main/Database/base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta name="Description" content="Information architecture, Web Design, Web Standards." />
<meta name="Keywords" content="your, keywords" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Distribution" content="Global" />
<meta name="Author" content="Erwin Aligam - ealigam@gmail.com" />
<meta name="Robots" content="index,follow" />

<link rel="stylesheet" href="images/MarketPlace.css" type="text/css" />

<LINK REL="SHORTCUT ICON"
       HREF="favicon.ico">

<title>Musicians Village - <?=$_SESSION['Username']?>'s Profile</title>

</head>

<body>

<!-- wrap starts here -->
<div id="wrap">

<!--header -->
<div id="header">			

	<div id="header-links">
	<p>
	<?php
		if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
		{
 	?>
    				<p>Logged in as: <a href="profile.php"><b><?=$_SESSION['Username']?></a></b> | Account: <?=$_SESSION['AccountType']?> | <a href="logout.php">Logout</a> </p>

	<?php
		}
		else
		{
	?>
			<p>Welcome <b>Guest</b>, Please <a href="login.php">Login</a> or <a href="register.php">Register</a></p>
	<?php
		}
	?>

    

	</p>		
	</div>		

<!--header ends-->					
</div>

<div id="header-photo"></div>		

<!-- navigation starts-->	
<div  id="nav">
	<ul>
		<li><a href="index.php">Home</a></li>
		<li><a href="login.php">Login</a></li>
		<li><a href="register.php">Register</a></li>			
		<li><a href="track.php?action=upload">Submit Track</a></li>
		<li><a href="track.php?action=listen">Listen To Tracks</a></li>
		<li><a href="/forums">Forums</a></li>
		<li><a href="contact.php">Contact</a></li>		
	</ul>
<!-- navigation ends-->	
</div>					

<!-- content-wrap starts -->
<div id="content-wrap" class="three-col"  >	

	<div id="sidebar">


		<h1>Sponsors</h1>
		<ul class="sidemenu">				
			<li><a href="index.html">Home</a></li>
			<li><a href="#TemplateInfo">Template Info</a></li>
			<li><a href="#SampleTags">Sample Tags</a></li>
			<li><a href="http://www.styleshout.com/">More Free Templates</a></li>	
			<li><a href="http://www.4templates.com/?aff=ealigam">Premium Templates</a></li>	
		</ul>	


	<!-- sidebar ends -->		
	</div>

	<div id="rightcolumn">

		<h1>Forum Stats</h1>
		<p>Top poster stuff here</p>

		<h1>*Newest track</h1>
		<p>it is here too! </p>				

	</div>


	<div id="main">

		<a name="MainHead"></a>



	<?php

	if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
	{
	?>

		<h1><?=$_SESSION['Username']?>'s Profile</h1>

	<?php


		$Administrator = "Administrator";
		$AccountQurey = $_SESSION['AccountType'];

		$User = $_SESSION['Username'];
		$Email = $_SESSION['EmailAddress'];
		$AccTyp = $_SESSION['AccountType'];
		$AccountIP = $_SESSION['AccountIP'];


		$action = $_GET['change'];
		$Picture = "pic";
		$EmailChange = "email";
		$member = $_GET['member'];
		$memberID = (isset($_GET['member']) ? $_GET['member'] : '');
		$Password = "password";
		$Start = "";

		if ($action == $Start) {
		?>
			<center>
				<img src="<?=$_SESSION['AccountPic']?>" width="130" height="130">
				<br />
				<a href="profile.php?change=pic">[Change Picture]</a>
				</center>
				<br />

				<?php
				echo "<b>Username:</b> $User";
				?>
				<br />
				<?php
				echo "<b>IP Address:</b> $AccountIP";
				?>
				<br />
				<?php
				echo "<b>Email Address:</b> $Email <a href=\"profile.php?change=email\">[Change]</a>";
				?>
				<br />
				<?php
				echo "<b>Account Type:</b> $AccTyp";
				?>
				<br />

		<?php
				if($AccountQurey == $Administrator)
				{
					echo "<b>Administrator:</b> Yes";
				}
				else
				{
					echo "<b>Administrator:</b> No";
				}


		}
		elseif(isset($_GET['member']))
		{
			if(is_numeric($_GET['member']))
			{
				// get the member id
				$memberID = (int) $_GET['member'];

				// Select only the row that matches memberID being requested, eg 123
				$query = "SELECT * FROM members_table WHERE memberID = '$memberID'";
				$result = mysql_query($query);

				// check that the query returned one row, meaning a match was found
				if(mysql_num_rows($result) == 1)
				{
					// grab the results from the query
					$row = mysql_fetch_assoc($result);

					// display profile here
				   printf('<pre>%s</pre>', print_r($row, true));
				}
				// a match was not found. Display an error instead
				else
				{
					echo '<p style="color:red">Member does not exists</p>';
				}
			}

			// Either the member id was not declared or it was invalid. Display an error
			else
			{
				echo 'Invalid member id specified';
			}
		}

		// Ending the profile main profile.php.


		// Starting the Picture upload area (profile.php?change=picture

		elseif ($action == $Picture) {

			$username = mysql_real_escape_string($_SESSION['Username']);
			$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
			$row = mysql_fetch_array($checklogin);
			$AccountPic = $row['ProfilePic'];
			$_SESSION['AccountPic'] = $AccountPic;

			$actionTWO = (isset($_GET['complete']) ? 'complete' : null);
			$Complete = "complete";


			if ($actionTWO == $Complete)
			{
				$picUPDATE = mysql_real_escape_string($_POST['picture']);
				$picUPDATEUSR = mysql_real_escape_string($User);
				$changepic = mysql_query("UPDATE  `a7331843_account`.`users` SET  `ProfilePic` =  '".$picUPDATE."' WHERE  `users`.`Username` = '".$picUPDATEUSR."' LIMIT 1 ");
				$username = mysql_real_escape_string($_SESSION['Username']);
				$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
				$row = mysql_fetch_array($checklogin);
				$AccountPic = $row['ProfilePic'];
				$_SESSION['AccountPic'] = $AccountPic;
				?>
				<meta http-equiv="REFRESH" content="0;url=profile.php"></HEAD>
				<?php
			}

		?>

		<center>

				<p>Current Picture:</p>

				<img src="<?=$_SESSION['AccountPic']?>" width="130" height="130">
				<br />
					<form method="post" action="profile.php?change=pic&complete" name="registerform" id="registerform">
					<fieldset>
						<label for="picture">Picture URL:</label><input type="text" name="picture" id="picture" /><br />
						<br />
						<input type="submit" name="register" id="register" value="Change Picture" />
					</fieldset>
					</form>

		</center>

		<?php
		}

		elseif ($action == $EmailChange) {

			$username = mysql_real_escape_string($_SESSION['Username']);
			$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
			$row = mysql_fetch_array($checklogin);
			$AccountPic = $row['ProfilePic'];
			$_SESSION['AccountPic'] = $AccountPic;

			$actionTWO = (isset($_GET['complete']) ? 'complete' : null);
			$Complete = "complete";


			if ($actionTWO == $Complete)
			{
				$picUPDATE = mysql_real_escape_string($_POST['email']);
				$picUPDATEUSR = mysql_real_escape_string($User);
				$changepic = mysql_query("UPDATE  `a7331843_account`.`users` SET  `EmailAddress` =  '".$picUPDATE."' WHERE  `users`.`Username` = '".$picUPDATEUSR."' LIMIT 1 ");
				$username = mysql_real_escape_string($_SESSION['Username']);
				$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."'");
				$row = mysql_fetch_array($checklogin);
				$Email = $row['EmailAddress'];
				$_SESSION['EmailAddress'] = $Email;
				?>
				<meta http-equiv="REFRESH" content="0;url=profile.php"></HEAD>
				<?php
			}

		?>

		<center>

			<p>Current Email: <?$Email?></p>
			<br />
			<form method="post" action="profile.php?change=email&complete" name="registerform" id="registerform">
			<fieldset>
					<label for="picture">New Email:</label><input type="text" name="email" id="email" /><br />
					<br />
					<input type="submit" name="register" id="register" value="Change Email" />
			</fieldset>
			</form>


		</center>

		<?php
		}

	}
	else
	{

		echo "<h1>Error</h1>";
		echo "<p>You need to be logged in to see your profile!</p>";

	}
	?>

		<br />

		</p>  


	</div>

<!-- content-wrap ends-->	
</div>

<!-- footer starts -->			
<div id="footer-wrap"><div id="footer">				

		<p>
		© 2006 <strong>Your Company</strong> | 
		Design by: <a href="http://www.styleshout.com/">styleshout</a> | 
		Valid <a href="http://validator.w3.org/check?uri=referer">XHTML</a> | 
		<a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>

   		      

		<a href="index.html">Home</a> | 
   		<a href="index.html">Sitemap</a> | 
   	<a href="index.html">RSS Feed</a>
		</p>		

</div></div>
<!-- footer ends-->	

<!-- wrap ends here -->
</div>

</body>
</html>

 

Link to comment
Share on other sites

My code is only an example. You will need to modify it in order for it work properly, for example you need to change where it says members_table with the name of the table that holds your users. memberID will also need to be changed to the field that holds your members id's

$query = "SELECT * FROM members_table WHERE memberID = '$memberID'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.