Twister1004 Posted October 23, 2008 Share Posted October 23, 2008 Hey everyone, I'm needing to understand how to use a $_GET action. When ever i use it it doesnt work, or tells me there is an undefined variable. I do not need forms for get, but perhaps a way to call it from somewhere else. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 23, 2008 Share Posted October 23, 2008 huh? im not understanding can you break it down a little more Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 23, 2008 Author Share Posted October 23, 2008 Ok, basically I just need to figure out how it works and how i can use it at any time i need it, besides using it in forms. Quote Link to comment Share on other sites More sharing options...
.josh Posted October 23, 2008 Share Posted October 23, 2008 GET method is where you pass a var=value through the URL like so:  page1.php echo "<a href = 'page2.php?foo=bar'>page2</a>";  page2.php <?php  echo $_GET['foo']; // output: bar ?> Quote Link to comment Share on other sites More sharing options...
prexep Posted October 23, 2008 Share Posted October 23, 2008 $_GET[name]  http://www.phpfreaks.com/index.php?name=This%20is%20the%20stuff  The $_GET[name] will look for the name and if true equals the value after the =. So $_GET[name] has in it now "This is the stuff" which it gets from the URL.  Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 23, 2008 Share Posted October 23, 2008 i have a blog, what i use get for is when i need to pass a variable (like an id number) to a link, so when somebody clicks one of my entries, it takes them to a new page where they can login and add comments, but only displays that entry  like so  print '<a href="/something.php?id=' . $entry_id . '">this goes to one specific entry</a>  the question mark tells php that the next thing in the url is a key to the GET array that you are defining at that moment, then there will be an equals sign and then the value of the get key  so it links to a page that has all the php on it to display 1 entry except the db query is incomplete, it needs an id number, so near the top of the page you use $id = $_GET['id'], that pulls the variable from the url and then you can stick it in your query (SELECT * FROM entries WHERE id=$id)  also if you want to put more than one variable in your url use & between them  <a href="/something.php?id=' . $entry_id . '&var=' . $var .'">  and that is what i use GET for Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 23, 2008 Author Share Posted October 23, 2008 @Crayon --------- Honestly, I had no idea what you were trying to tell me. I didn't understand how to use it. Thanks though.  @prexep -------- That kinda helped in a way. Thanks  @lodious -------- This made a WHOLE lot more since. I'm going to try and see if I understand it now. Be back in like 5 minutes =) Quote Link to comment Share on other sites More sharing options...
Maq Posted October 23, 2008 Share Posted October 23, 2008 @Crayon --------- Honestly, I had no idea what you were trying to tell me. I didn't understand how to use it. Thanks though.  @prexep -------- That kinda helped in a way. Thanks  @lodious -------- This made a WHOLE lot more since. I'm going to try and see if I understand it now. Be back in like 5 minutes =)  Best way to understand this is to make 2 scripts and test it out yourself.. Just use CV's example. This is a basic PHP method of passing data to another page. Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 23, 2008 Author Share Posted October 23, 2008 I'm getting it now! However, When i try to link it to another page, it isnt executing correctly. Â How would i be able to use it inside a link? could i have to do this? <div style = "position:absolute; left:501px; top:-4px;"> <a href = <?php echo " "cp.php?user='.$username.'" "; ?> >profile</a> </div> Â OR some other way? Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 23, 2008 Share Posted October 23, 2008 <a href="' <?php echo cp.php?user=$username; ?>'" >profile</a> Â try that Quote Link to comment Share on other sites More sharing options...
Altec Posted October 23, 2008 Share Posted October 23, 2008 For example, say I had three phrases. If Bob comes along, I want to say "Hi, Bob!" If Frank comes along, I want to say "Hi, Frank!" Perhaps a stranger comes along. I might want to just nod and give a quick hi.  On my page I would have three links: one for Bob, one for Frank, and one for the stranger.  <a href="say.php?person=bob">Bob</a> <a href="say.php?person=frank">Frank</a> <a href="say.php?person=stranger">Stranger</a>  Notice how I am "passing" the person to the script "say.php" throught the URL. Let's start say.php:  <?php $person = $_GET['person']; ?>  That says "I want to define variable Person to the value of the Person variable passed in the URL." Now we just need to use either A) An IFTHEN, ELSEIF, ELSE structure or B) A switch function. Both these options will decide which phrase to say depending on the person.  <?php $person = $_GET['person']; $phrases = array(   'bob'   => 'Hi, Bob!',   'frank'  => 'Hi, Frank!',   'stranger' => '*nods* Hi.', ); // IFTHEN, ELSEIF, ELSE if($person == $phrases['bob']) {   echo $phrases['bob']; // Bob walks by } elseif($person == $phrases['frank']) {   echo $phrases['frank']; // Frank walks by } else {   // Must be a stranger   echo $phrases['stranger']; } // Switch function switch($person) {   case 'bob':     echo $phrases['bob']; // Bob walks by   break;     case 'frank':     echo $phrases['frank']; // Frank walks by   break;     case 'stranger':     echo $phrases['stranger']; // A stranger walks by   break;     default:     echo 'No one has walked by.';   break; } ?> Quote Link to comment Share on other sites More sharing options...
Maq Posted October 23, 2008 Share Posted October 23, 2008 profile Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 23, 2008 Author Share Posted October 23, 2008 @Maq ------ When I go to cp.php (Clicking the link) I am getting a undefined Index in the URL. So that means I did it 50%, In a way. Â @Altec ------- I have no idea what what you used in your code. I could guess, but Id rather figure out the $_Get first for the URL =P. Â @lodius ------- I used, it and it just came out as an Error. But I believe Maq fixed it. Â Â Cerious, do any of you have TeamViewer to make this easier? Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 23, 2008 Share Posted October 23, 2008 yeah i see my mistake now Quote Link to comment Share on other sites More sharing options...
Maq Posted October 23, 2008 Share Posted October 23, 2008 @Maq ------ When I go to cp.php (Clicking the link) I am getting a undefined Index in the URL. So that means I did it 50%, In a way.  Sorry could you elaborate, what's the exact error? Are you in the same directory you're calling this page from? Quote Link to comment Share on other sites More sharing options...
Altec Posted October 23, 2008 Share Posted October 23, 2008 I'm not really sure how that will help you... (Team Viewer) Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 23, 2008 Author Share Posted October 23, 2008 OK, when I'm on the front page, of the site (The link to get to cp.php) I click the profile link (cp.php) when i got there, this is listed in my URL http://5.3.17.155/dreamweaver%20sites/abysmal-essence/cp.php?user=%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20variable:%20username%20in%20%3Cb%3EC:\Documents%20and%20Settings\Compaq_Owner\Desktop\Server%20Files\Web%20Server\xampp\htdocs\dreamweaver%20sites\Abysmal-Essence\header.php%3C/b%3E%20on%20line%20%3Cb%3E51%3C/b%3E%3Cbr%20/%3E Â and this is on the page. Notice: Undefined index: username in C:\Documents and Settings\Compaq_Owner\Desktop\Server Files\Web Server\xampp\htdocs\dreamweaver sites\Abysmal-Essence\cp.php on line 4 Â If you would like to view the whole file, i will gladly share it. (The files are 2 separate things. header.php which has all the login stuff and all that stuff. and cp.php which loads the whole profile.) Â If you are cerious, about team viewer, it is kind of like a remote assistance kind of thing. Except it is less stressing for the computer. It stresses the net and relies on the person's RAM. Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 23, 2008 Author Share Posted October 23, 2008 I've tried and I've tried, I just can't seem to fix what ever the problem is *Sigh* any other suggestions? Â Also, what ever it is saying "Undefined Index" is really making me mad. I can't figure out what it is trying to say. Â Anyone with an idea what that is trying to tell me and how it could be fixed? It is driving me insaine. That is about all the errors i get now, Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 23, 2008 Author Share Posted October 23, 2008 Any idea to keep going on the same track? Im just about to figure it out! I need a needle to get the rest through my head (meaning i need a spark to get it.) Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 24, 2008 Author Share Posted October 24, 2008 Wow, the edit thing should be enables for the last message the person wrote. o.o   Anyways, I've played around all day with codes, and I'm not getting any errors now, however the code isnt executing for the URL. any ideas? ._.  Edit: Nvm, I'm now getting a error X_X Notice: Undefined index: username in C:\Documents and Settings\Compaq_Owner\Desktop\Server Files\Web Server\xampp\htdocs\dreamweaver sites\Abysmal-Essence\cp.php on line 3  If you would like to view the page, here ya go, <?php session_start(); ?> <?php error_reporting(E_ALL);?> <?php $username = $_GET['username']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="style.css" rel="stylesheet" type="text/css" /> <title>Abysmal Essence | Control Pannel</title> <style> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF; } body { background-color: #000000; background-image: url(images/bg-soft.PNG); background-repeat: repeat; } #loggedin_info { position:absolute; left:159px; top:100px; width:218px; height:400px; z-index:1; margin:auto; padding:0px; } #header{ position:absolute; background:#000000; top:2px; left:100px; } #notloggedin{ position:absolute; left: 405px; top: 198px; width: 444px; height: 32px; } #content_loggedin{ position:absolute; top:99px; left:381px; width: 528px; height: 399px; } #side_rename{ position:absolute; top:99px; left:920px; width: 189px; height: 401px; } #nav{ position:absolute; left:4px; top:102px; width:145px; height:388px; color:white; background:#4682B4; } #button_account{ position:absolute; top:473px; left:209px; width: 150px; } #content_account{ position:absolute; top:472px; left:586px; } #unknown_account{ position:absolute; top:474px; left:955px; } </style> </head> <body> <div id = login> <?php include('header.php'); $result = mysql_query("SELECT about,content,unknown FROM `profile` WHERE `accountid` = {$_SESSION['login_id']}"); if (!$result) {   echo 'Could not run query: ' . mysql_error();   exit(); } $row = mysql_fetch_row($result); $getuser = mysql_query("SELECT * FROM `accounts` WHERE `username` = '$username'"); /* //Get users progile id $profileid = $_REQUEST['username']; // you'll need to change the values here to suit your db $query1 = "SELECT * FROM `accounts` WHERE `username` = '$profileid'"; $result1 = mysql_query($query1) or die ("There was an error"); $row1 = mysql_fetch_row($result1);*/ ?> </div> <?php if (isset($_SESSION['login_user'])){ ?> <div id="loggedin_info"> <p align = center> About me, <br/><?php echo htmlentities($row[0]); ?></p> </div> <div id = content_loggedin>  <p align = center>About your self,<br/> <?php echo htmlentities($row[1]); ?></p> </div> <div id = side_rename>  <p align = center>Personal Use <br/><?php echo htmlentities($row[2]); ?></p> </div> <?php } else{ ?>  <div id = notloggedin>   <center> <strong>You must be loggedin to view your profile!</strong><br/> The profiles is currently, not done, or functional. Please wait while we get this online, ASAP!<br/> Thank you!</center></div> <?php } ?> <div id = nav> <center> <hr /> <a href = "./index.php">Home</a><br/><hr /> <a href = "./faq.php">FAQ</a><br/><hr /> <a href = "./about.php">About Us</a><br/><hr /> <a href = "./index.php">Projects</a><br/><hr /> </center> </div> </body> </html>  I'm so sorry I sound like a nub, however, Learning PHP isn't easy just learning it online. ._. Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 24, 2008 Author Share Posted October 24, 2008 Is anyone willing to help me? IF not, then I guess its back to the website learning to see what I can do. Quote Link to comment 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.