RyanSF07 Posted September 2, 2009 Share Posted September 2, 2009 Hi Guys, I'm trying to figure this out and thought I'd post the bare bones here to see if a second pair of eyes might see the fix faster: I setting an using $_GET[id] in two parts of the page/code, but the in last instance it fails to display. I've trimmed the code to highlight where the problem occurs. I use more or less this same code on pages where the SQL query doesn't not include ORDER BY RANDOM and it works without trouble. Is ORDER By Random causing the problem? <?php session_start(); $sql = "SELECT * FROM video, registered_users WHERE video.user_id = registered_users.id ORDER BY RAND() LIMIT 1"; $query_result = mysql_query($sql); $row = mysql_fetch_array($query_result); $_SESSION[get] = $row[id]; $row[id] = $_GET[id]; $video_body = nl2br($row[video]); $quizvideo = <<<EOD $video_body EOD; $quizcontent .= <<<EOD <p><b>$row[title]</p></b> <p>$row[description_text] </p> $quizvideo <iframe src="show_questions.php?id=$_GET[id]" ... (NOTE: $_GET[id]; works here) EOD; $embedquiz .= " add this quiz to your website<br> <br> <iframe src="http://www.site.com/view_quiz_inframe.php?id=$_GET[id]..... (NOTE: $_GET[id]; DOES NOT WORK HERE -- ....</iframe> ...... ?> Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/ Share on other sites More sharing options...
TeNDoLLA Posted September 2, 2009 Share Posted September 2, 2009 Your code is all the way pretty terrible. And you should use single quotes around the indexses in arrays $_GET[id] --> $_GET['id']. In the second time you TRY to use $_GET['id'] it is not parsed by php at all. It is just part of the string $embedquiz. And also you are not ending that string with quotation mark & semicolon which should lead in to error. If you want to use php variable inside string you could do: <?php $someString = 'Testing diipa daapa and id is : ' . $_GET['id'] . ' and the string continues..'; Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/#findComment-911029 Share on other sites More sharing options...
RyanSF07 Posted September 2, 2009 Author Share Posted September 2, 2009 I just tried using $_SESSION[get] in place of GET in that second instance and it seems to be working. Thanks TeNDoLLA for the suggestion to use ' . $_GET['id'] . ' I'll try it and post back. Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/#findComment-911033 Share on other sites More sharing options...
RyanSF07 Posted September 2, 2009 Author Share Posted September 2, 2009 It threw the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING I'll play around with it some. Thanks again Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/#findComment-911038 Share on other sites More sharing options...
TeNDoLLA Posted September 2, 2009 Share Posted September 2, 2009 You can read from here why $_GET[id] is bad and why you should use $_GET['id'] instead. http://www.nusphere.com/kb/phpmanual/language.types.array.htm Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/#findComment-911040 Share on other sites More sharing options...
dcreeves88 Posted September 2, 2009 Share Posted September 2, 2009 I'd store $_GET['id'] in it's own variable $id = $_GET['ID']; then create the link as such http://www.site.com/view_quiz_inframe.php?id=urlencode($id) But that's just me, could be wrong. Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/#findComment-911054 Share on other sites More sharing options...
TeNDoLLA Posted September 2, 2009 Share Posted September 2, 2009 Yes I would do that also, but the point was using the quotes around literal array indexes. Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/#findComment-911100 Share on other sites More sharing options...
dcreeves88 Posted September 2, 2009 Share Posted September 2, 2009 Agreed TeNDoLLA. Link to comment https://forums.phpfreaks.com/topic/172856-solved-where-did-my-_getid-go/#findComment-911101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.