Solved

Passing variable through inline html

Posted on 2012-03-29
7
419 Views
Last Modified: 2012-03-29
I'm trying to pass a PHP variable through an inline html form.  A user clicks on a link that pulls up information regarding a quiz topic.  The link specifies the variables, but when I use the GET method, since it's the same page, the variable is unknown.  

I'm using the colorbox method.

      <td ' . $row_color . '><span class="boldblacklinks"><a class="example8" href="?topicid='.$topicid.'&quizid='.$quizid.'">Read Topic Introduction</span></a></td>            

The inline html is coded as :       <div style='display:none'>
                  <div id='inline_example1' style='padding:10px; background:#fff;'>
                        <?php
echo '<form action="" method="post">';


            $topicid = $_POST['topicid'];

      $sql2 = "SELECT info FROM tr_topics WHERE topicid = '".$topicid."'";      
      
      echo $sql2 . '<br /><br />';
      
      $res2 = mysql_query($sql2) or trigger_error(mysql_error(),E_USER_ERROR);
      $row2 = mysql_fetch_row($res2);

      $explanation = $row2[0];

      echo nl2br($explanation) . '<br /><br />';

      
      echo '<div align="center">
                        <input type="submit" name="submit" value="Continue to the video potion of the training" class="nobutton">
              </div>';
echo '</form>';?>
            </div>
            </div>
0
Comment
Question by:t3chguy
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:Scott Madeira
ID: 37782525
Not totally sure I understand the question but your form is using POST but you are talking about GET.  I'd start there...
0
 
LVL 1

Author Comment

by:t3chguy
ID: 37782561
basically the link is supposed to open a colorbox to run a query and display information...but the colorbox is stored in 'inline html', so technically i'm trying to use the variable from earlier in the page in a lightbox.

But the page isn't changing the topicid when i click on a new link .

I've attached two images.  The quiz one...each 'Read Topic Introduction' link is pointing to the correct topic id...but regardless of which one i open they all point to the same topic id.
quiz.jpg
colorbox.jpg
0
 
LVL 14

Expert Comment

by:Scott Madeira
ID: 37782592
You need to attach all of the relevant php files so we can see how you are doing it.  The small section of code provided isn't sufficient to solve the problem.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 1

Author Comment

by:t3chguy
ID: 37782594
<?php

$programid = "1000";

require_once($_SERVER['DOCUMENT_ROOT']."/includes/verifyaccess.php");
require_once($_SERVER['DOCUMENT_ROOT']."/includes/mainfunctions.php");
require_once($_SERVER['DOCUMENT_ROOT']."/includes/header.php");

//Make sure the last four of the ssn matches somebody in hr_employeeinfo
$fourssn = $_POST['fourssn'];

if ($fourssn == '' || $fourssn == '0')
      {
      echo "<span class='errormessagered'>You are not currently logged into the training system.  Please try again.</span>";
      echo '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';
      require_once($_SERVER['DOCUMENT_ROOT']."/includes/footer.php");      
      die;
      }

//Use the last four to validate users identity
$validateusr = "SELECT respid FROM hr_employeeinfo WHERE ssn = '".$fourssn."'";
$validateres = mysql_query($validateusr) or trigger_error(mysql_error(),E_USER_ERROR);
$validaterow = mysql_fetch_row($validateres);

$loggedinuser = $validaterow[0];

$loggedinusrnm = "SELECT ckname, location FROM pr_resp WHERE respid = '".$loggedinuser."'";
$loggedinusrres = mysql_query($loggedinusrnm) or trigger_error(mysql_error(),E_USER_ERROR);
$namerow = mysql_fetch_row($loggedinusrres);

$employeename = $namerow[0];
$employeelocation = $namerow[1];

$gettopicid = $_POST['topicid'];
$getquizid = $_POST['quizid'];
$readinfo = $_POST['readinfo'];

$watchedvideo = $_POST['watchedvideo'];

echo "<span class='sectitleblk'>Welcome to the online training portal.  Below is a list of mandatory trainings. </span><br /><br />
Welcome to the Lifting Gear Hire Corporation Online Training System. This online training has been designed to enhance your skills, increase your performance, and meet the current OSHA training requirements.

Most videos are between 15 and 20 minutes in length, so please make sure to have time prior to complete both the video and the quiz.
 
 If you do not finish, you can close at anytime within the quiz and continue on from your previously saved step.
 
The quizzes have been structured so that everybody can pass them. If you answer a question wrong, you will get a second chance to answer the question after reviewing some literature regarding that question.
<br /><br />
The entire process should take between 30-45 minutes to complete. Upon completion, you will receive a certificate acknowledging your completion.

Follow the steps in the table below to assure you successfully complete the training.  There are three steps required in order to complete the training.

Each section will display a complete button for you to press, which will allow you to continue.  

<span class='errormessagered'>Simply hitting the back button will not generate the proper links to continue!</span><br /><br >";

//This looks for respid for the time being but eventually will need to make sure this changes to last four of ssn identification

echo '<table width="50%" cellspacing="0" cellpadding="0" border="0">';
echo '<tr>
            <td class="columnheader"><strong>Quiz Name</strong></td>
            <td class="columnheader"><strong>Duration</strong></td>
            <td class="columnheader"><strong>Due Date</strong></td>
            <td class="columnheader"><strong>Read Intro</strong></td>
            <td class="columnheader"><strong>Watch Video Taken</strong></td>
            <td class="columnheader"><strong>Take Quiz</strong></td>
        </tr>';

$sql = "SELECT tr_topics.topicid, topicname, frequency
            FROM tr_topics
            LEFT JOIN tr_posrequirements ON tr_topics.topicid = tr_posrequirements.topicid
            LEFT JOIN tr_locrequirements ON tr_topics.topicid = tr_locrequirements.topicid
            LEFT JOIN hr_positions ON tr_posrequirements.positionid = hr_positions.id
            LEFT JOIN hr_employeeinfo ON hr_positions.id = hr_employeeinfo.positionid
            WHERE tr_topics.hidden = '0' and respid = '".$respid."'";
      
$res = mysql_query($sql) OR trigger_error(mysql_error(),E_USER_ERROR);
$num = mysql_num_rows($res);

for ($a = 0; $a < $num; ++$a)
      {
      $topicid = mysql_result($res,$a,0);
      $topicname = mysql_result($res,$a,1);
      $frequency = mysql_result($res,$a,2);
                  
      $sql2 = "SELECT tr_quiz.quizid, quizname, numquestions, topicid, tr_quiz.videoid, length, datecompleted, position
                   FROM tr_quiz LEFT JOIN tr_quizlog ON tr_quiz.quizid = tr_quizlog.quizid
                   LEFT JOIN tr_videos ON tr_quiz.videoid = tr_videos.videoid
                   WHERE tr_quiz.hidden = '0' and topicid = '".$topicid."'";            
      $res2 = mysql_query($sql2) or trigger_error(mysql_error(),E_USER_ERROR);
      $num2 = mysql_num_rows($res2);

      for($b = 0; $b < $num2; ++$b)
            {
            $quizid = mysql_result($res2, $b, 0);
            $quizname = mysql_result($res2, $b, 1);
            $numquestions = mysql_result($res2, $b, 2);
            $videoid = mysql_result($res2,$b,4);
            $videotime = mysql_result($res2,$b,5);
            $lastdatetaken = mysql_result($res2, $b, 6);
            $position = mysql_result($res2, $b, 7);
            
            $quiztime = '00:10:00';
            
            echo $videotime . ' + ' . $quiztime . '<br />';
            
            
            $duration = $videotime + $quiztime;
            
      
            
            $color_A = 'class="alt2_1"';
            $color_B = 'class="alt2_2"';

            $row_color = ($a % 2) ? $color_A : $color_B;

            
            if ($position == '0' || $position == '' || $position == NULL)
                  {
                  $position = '1';
                  }
            
            if($position > '1' || $readinfo == '1' && $topicid == $gettopicid && $quizid == $getquizid)
                  {
                  $displayvideolink = "<span class='boldblacklinks'><a href='watchvideo.php?topicid=".$topicid."&quizid=".$quizid."&videoid=".$videoid."'>Watch Video</span></a>";
                  }
                  
            else
                  {
                  $displayvideolink = '';
                  }
                  
            if ($position == '1' || $position == '' || $position == '0')
                  {
                  $linktext = "Start Exam";
                  }
                  
            else
                  {
                  $linktext = "Resume Saved Version";
                  }
                  

            if ($position > '1' || $watchedvideo == '1' && $readinfo == '1' && $topicid == $gettopicid && $quizid == $getquizid)
                  {
                  $displayquizlink = "<span class='boldblacklinks'><a href='quiz.php?topicid=".$topicid."&quizid=".$quizid."&videoid=".$videoid."&position=".$position."'>".$linktext."</span></a>";
                  }
                  
            else
                  {
                  $displayquizlink = "";
                  }
                                    
      }
      
            }
?>                  

                  
      <?            
            echo '<tr>
                        <td ' . $row_color . '>' . $quizname . '</td>
                        <td ' . $row_color . '>' . $duration . '</td>
                        <td ' . $row_color . '>' . $duedate . '</td>
                        <td ' . $row_color . '><span class="boldblacklinks"><a class="example8" href="?topicid='.$topicid.'&quizid='.$quizid.'">Read Topic Introduction</span></a></td>            
                        <td ' . $row_color . '>' . $displayvideolink . '</td>            
                        <td ' . $row_color . '>'.$displayquizlink.'</span></a></td>
                  </tr>';
                  
                  ?>
            <div style='display:none'>
                  <div id='inline_example1' style='padding:10px; background:#fff;'>
                        <?php
      // $topicid = $_POST['topicid'];
      $sql2 = "SELECT info FROM tr_topics WHERE topicid = '".$topicid."'";      
      echo $sql2 . '<br /><br />';
      $res2 = mysql_query($sql2) or trigger_error(mysql_error(),E_USER_ERROR);
      $row2 = mysql_fetch_row($res2);
      $explanation = $row2[0];
      echo nl2br($explanation) . '<br /><br />';
      echo '<div align="center">
                        <input type="submit" name="submit" value="Continue to the video potion of the training" class="nobutton">
              </div>';
?>
      </div>
            </div>
                  
                  <?


      
echo '</table><br /><br />';
      
require_once($_SERVER['DOCUMENT_ROOT']."/includes/footer.php");

?>
0
 
LVL 1

Author Comment

by:t3chguy
ID: 37782599
Color box script:


            <script>
                  $(document).ready(function()
                        {
                        //Examples of how to assign the ColorBox event to elements
                        $("a[rel='example1']").colorbox();
                        $("a[rel='example2']").colorbox({transition:"fade"});
                        $("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
                        $("a[rel='example4']").colorbox({slideshow:true});
                        $(".example5").colorbox();
                        $(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
                        $(".iframe").colorbox({width:"90%", height:"90%", iframe:true});
                        $(".iframe800").colorbox({width:"800px",height:"500px",iframe:true, resize:false});
                        $(".iframetall").colorbox({width:"800px",height:"650px",iframe:true, resize:false});
                        $(".iframetall70").colorbox({width:"70%",height:"90%",iframe:true, resize:false});
                        $(".example8").colorbox({width:"80%",height:"500px", inline:true, href:"#inline_example1"});
                        $(".example9").colorbox({
                              onOpen:function(){ alert('onOpen: colorbox is about to open'); },
                              onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
                              onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
                              onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
                              onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
                              });
                        //Example of preserving a JavaScript event for inline calls.
                        $("#click").click(function(){
                              $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
                              return false;
                        });
                        });
            </script>
0
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 500 total points
ID: 37782921
I still don't understand what you are trying to do...  From the looks of the code it will only print one table row because your <tr> and <td>s are outside both of your $a and $b loops so in that part of the HTML the topicId will only be set to the last value.

In general, if you want to use $_POST or $_GET you need to click the link or hit the button that then calls the server.  When the page is reloaded you will have access to those variables.

If you are never leaving the page then you need a way to pass the topicID into your javascript to do what you want it to do.  you will need to modify the colorbox code to accept your input variable and then execute the correct function.  I'm not familiar with colorbox to be able to assist further than that.
0
 
LVL 1

Author Closing Comment

by:t3chguy
ID: 37782985
Thank you for that information, I think I'm going to build a temporary table to hold the values for whether or not they have read the intro, and watched the video.  That way, I'm not worried about passing values back and forth as I was before.  

While, this hasn't been resolved, as I'm thinking this is quite out of the realm of possibilities, you still helped me change my line of thinking.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question