ChrisMartino Posted January 17, 2010 Share Posted January 17, 2010 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 :/ Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/ Share on other sites More sharing options...
Buddski Posted January 17, 2010 Share Posted January 17, 2010 $member = (isset($_GET['member']) ? $_GET['member'] : ''); This is a single little example but you can go even simpler and use $member = $_GET['member']; Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996675 Share on other sites More sharing options...
ChrisMartino Posted January 17, 2010 Author Share Posted January 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996713 Share on other sites More sharing options...
wildteen88 Posted January 17, 2010 Share Posted January 17, 2010 How/where is $member and $memeberID being defined? Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996720 Share on other sites More sharing options...
ChrisMartino Posted January 17, 2010 Author Share Posted January 17, 2010 $member = "member"; $memberID = (isset($_GET['member']) ? $_GET['member'] : ''); Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996721 Share on other sites More sharing options...
wildteen88 Posted January 17, 2010 Share Posted January 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996722 Share on other sites More sharing options...
ChrisMartino Posted January 17, 2010 Author Share Posted January 17, 2010 Well could you show me how to do it?, I want it so if they type profile.php?member=123 it would echo "123" how could i do that? Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996731 Share on other sites More sharing options...
wildteen88 Posted January 17, 2010 Share Posted January 17, 2010 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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996748 Share on other sites More sharing options...
ChrisMartino Posted January 17, 2010 Author Share Posted January 17, 2010 Ok, So i did what you said tried it and it worked , 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 - [email protected]" /> <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> Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996793 Share on other sites More sharing options...
wildteen88 Posted January 17, 2010 Share Posted January 17, 2010 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996806 Share on other sites More sharing options...
ChrisMartino Posted January 17, 2010 Author Share Posted January 17, 2010 Haha just relised that when you said it lmao, Its almost finished, Just working out the kinks, I've added your name to the credits list on my website do you have a website i can link too for you? Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996820 Share on other sites More sharing options...
ChrisMartino Posted January 17, 2010 Author Share Posted January 17, 2010 One last thing :/, I have this for there Display picture "<img src="<?$AccountPic?>" width="130" height="130">" now its not displaying the image yet when i do echo $AccountPic; it echos the picture directory exactly? Edit: Fixed! Quote Link to comment https://forums.phpfreaks.com/topic/188784-help-with-url/#findComment-996822 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.