Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Wed Jul 23, 2008 6:05 am Reply with quote

I am trying to enhance a form built using the phpBB template engine.

The form is for adding a new exam.

It only had two fields...Test Title and Year Used.

I am trying to add Exam Type.

Here is what it looks like so far:

Code:
if ( ($mode == 'add' ) &&( ( $userdata['user_level'] == ADMIN ) || ($courses['access_level'] == DIRECTOR) ) ){ 


                $nav_path .= ' - Add New Test';     
                 
                $template->assign_block_vars('quiz_form',array('ACTION' => append_sid('index.php'), 
                                                    'HIDDEN' => '<input type="hidden" name="ARG1" value="'.$cid.'">',
                                                    'HEAD' => 'Add New Test',
                                                    'LABEL' => '&nbsp;Create&nbsp;',
                                                    'CANCEL_LABEL' => 'Cancel',
                                                    'FORM_SUBMIT' => 'javascript:submit_form(document.quiz, \'addresp\')',
                                                    'FORM_CANCEL' => append_sid('index.php?action=show&ARG1='.$cid)                                                     
                                            ));
             
                $template -> assign_block_vars('quiz_form.info', array('NAME' => 'Test Title', 'VALUE' => '<input type="text" size="30" name="qname">',
                'NAME2' => 'Year Used', 'VALUE2' => '<select name="qyear" size="1">
                                                        <option>0001</option>
                                                        <option>0102</option>
                                                        <option>0203</option>
                                                        <option>0304</option>
                                                        <option>0405</option>
                                                        <option>0506</option>
                                                        <option>0607</option>
                                                        <option>0708</option>
                                                        <option>0809</option>
                                                        <option>0910</option>
                                                        </select>', //the block after the first NAME/VALUE pair above was added by SMQ on 1/6/05 to allow user to specify the 'year_used' for the newly created test - SMQs
                                                         
                    'NAME3' => 'Exam Type', 'VALUE3' => '<select name="exam_type" size="1">
                                                        <option value=\"NM\">Normal</option>
                                                        <option value=\"RM\">Remediation</option>
                                                        <option value=\"MU\">Makeup</option>                                                         
                                                        </select>')); //the block after the year used above was added by SFD on 7/9/08 to allow the addition of exam type - SFD

            } // eof add
            if ( ($mode == 'addresp' ) &&( ( $userdata['user_level'] == ADMIN ) || ($courses['access_level'] == DIRECTOR) ) ){
     
                $nav_path .= ' - Add New Test';
                 
                $template->assign_block_vars('quiz_form',array('ACTION' => append_sid('index.php?action=show&ARG1='.$cid), 
                                                    'HIDDEN' => '<input type="hidden" name="ARG1" value="'.$cid.'">',
                                                    'HEAD' => 'Add New Test - Response',
                                                    'LABEL' => '&nbsp;Test Home&nbsp;',
                                                    'FORM_SUBMIT' => 'javascript:submit_form(document.quiz, \'show\')',
                                                    'CANCEL_LABEL' => '',
                                                    'FORM_CANCEL' => append_sid('index.php?action=show&ARG1='.$cid)                                                     
                                            ));
             
             
                $sql= "INSERT INTO " .QUIZ_TABLE. " (course_id, quiz_name, year_used, exam_type, lockyn) VALUES ('".$cid."', '".$_POST['qname']."', '".$_POST['qyear']."', '".$_POST['exam_type']."', 'n')";//year_used and post request parameters added by SMQ on 1/6/05
                                                            //exam_type parameters added by SFD on 7/9/08
                if ( !$db->sql_query($sql) )
                {
                    $message = 'Error in Creating New Test!';
                }
                else {
                    $message = 'New Test has been created!';
                }

            $template -> assign_block_vars('quiz_form.info', array('NAME' => $message, 'VALUE' => '')); 


And here is the template:

Code:
<table width="100%" cellpadding="5" cellspacing="0" border="0"  align="center">


 <tr>
   <td align="left" valign="top" width="95%">
   <table width="100%" cellpadding="0" cellspacing="0" border="1"  class="bodyline">
   <tr>
      <td  height="240"  valign="top">

   <table width="100%" cellpadding="0" cellspacing="0" border="0">
<!-- BEGIN quiz -->
   <tr>
      <td>
         <table width="100%"  cellpadding="0" cellspacing="0" border="0">
         <th align="left" class="catHead">
               &nbsp;Tests&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               {quiz.NEW}
         </th>

         <tr>
            <td>
               <table width="90%"  cellpadding="3" cellspacing="0" border="0" align="center">
<!-- BEGIN info -->
               <tr>
                  <td align="left" valign="middle" class="nav">
                     {quiz.info.Q_NAME}
                  </td>
               </tr>   
               <tr>
                  <td align="left" valign="middle" class="genmed">&nbsp;&nbsp;
                      &nbsp {quiz.info.SET_VAL}&nbsp{quiz.info.LOCK}
                  </td>
               </tr>            
               <tr>
                  <td align="left" valign="middle" class="genmed">&nbsp;&nbsp;
                     Availability : &nbsp {quiz.info.AVAIL}
                  </td>
               </tr>
               <tr>
                  <td align="left" valign="middle">
                     <table width="90%"  cellpadding="2" cellspacing="0" border="0" align="left">
                     <tr>
                        <td width="4">&nbsp;&nbsp;&nbsp&nbsp;</td>
                        <td>
<!-- BEGIN options -->
                           <a href="javascript:void(0);" class= "action" onClick="{{quiz.info.options.VALUE}}">{quiz.info.options.NAME}</a>&nbsp;&nbsp;
<!-- END options -->
                        </td>
                     </tr>
                     </table>
                  </td>
               </tr>
               <tr><td height="12"></td></tr>         
<!-- END info -->
               </table>
   

            </td>
         </tr>
         </table>
      </td>
   </tr>
<!-- END quiz -->
<!-- BEGIN quiz_form -->
   <tr>
      <td>
         <table width="100%"  cellpadding="0" cellspacing="0" border="0">
         <th align="left" class="catHead">
            {quiz_form.HEAD}&nbsp;&nbsp;&nbsp;
         </th>
         <tr>
            <td>
               <form action="{quiz_form.ACTION}" method="post" name="quiz">
               {quiz_form.HIDDEN}
               <input type="hidden" name="action" />
               <table width="98%"  cellpadding="3" cellspacing="5" border="0" align="center">
<!-- BEGIN info -->
               <tr>
                  <td class="cattitle" width="20%">{quiz_form.info.NAME}</td>
                  <td class="gen">{quiz_form.info.VALUE}</td>
               </tr>
               <tr>
                  <td class="cattitle" width="20%">{quiz_form.info.NAME2}</td>
                  <td class="gen">{quiz_form.info.VALUE2}</td>
               </tr>
                    <tr>
                  <td class="cattitle" width="20%">{quiz_form.info.NAME3}</td>
                  <td class="gen">{quiz_form.info.VALUE3}</td>
               </tr>

<!-- END info -->
               <tr>
                  <td colspan="2">
         &nbsp;&nbsp;<a href="{quiz_form.FORM_SUBMIT}" class="action">{quiz_form.LABEL}</a> &nbsp;&nbsp; &nbsp;&nbsp;
         <a href="{quiz_form.FORM_CANCEL}"  class="action">{quiz_form.CANCEL_LABEL}</a>

                  </td>
               </tr>
               </table>
               </form>
            </td>
         </tr>
         </table>
      </td>
   </tr>
<!-- END quiz -->   

   <tr>
      <td height="12"></td>
   </tr>
   </table>


      </td>
   </tr>
   </table>
  </td>
</tr>
</table>

<br />


Everything looks good. The list box is visible. It creates the test but will not add the exam_type

I'm using enum ('NM','RM','MU') as my datatype for exam_type

I added this for error checking

Code:
print '<pre>'; var_dump($_POST); print '</pre>'; 


Quote:
array(5) {
["ARG1"]=>
string(2) "19"
["action"]=>
string(7) "addresp"
["qname"]=>
string(12) "Another test"
["qyear"]=>
string(4) "0809"
["exam_type"]=>
string(10) "\\\"RM\\\""
}


Why does the exam type look like this?

"\\\"RM\\\""


Another way...

Code:
 print "<pre>"; 

                    print_r($sql);
                    print "</pre>";


Quote:
INSERT INTO quiz (course_id, quiz_name, year_used, exam_type, lockyn) VALUES ('19', 'Another test', '0809', '\\\"RM\\\"', 'n')


Code:
'".mysql_real_escape_string($_POST['exam_type'])."'


did not work
 
View user's profile Send private message Visit poster's website ICQ Number
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Wed Jul 23, 2008 11:48 am Reply with quote

phpBB2 add slashes to escape all input coming from the user. So you would need to unescape it (using stripslashes)

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Donovan







PostPosted: Thu Jul 24, 2008 12:23 pm Reply with quote

Thanks. If it does not add slashes at the point of insertion then does it do it in the template.php or somewhere else?

assign_block_vars perhaps?
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©