2 Replies - 470 Views - Last Post: 22 November 2011 - 06:21 AM Rate Topic: -----

#1 carlbrooks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 19-November 11

I keep getting undefined index error

Posted 21 November 2011 - 07:11 PM

I have two php pages. One controls the form while the other displays a table. What my question is that I have spinner in the form which determines the number of questions, whatever number is displayed on that spinner, when the user submits it should display that same number of rows in the table.

for example if the Spinner = 25,then it should display 25 rows in the table and stating in the rows 1,2,3,4...up to 25 for the Question Id (<td class="qid">).

My problem is that I am getting an undefined index error everytime stating Notice: Undefined index: txtQuestion..... on line 42. I don't know why I am getting this error though as it should be able to find the index but for some strange reason it can't find the index. Do you know why?

Below is code for the spinner and submit button (create_session.php)

 <form action="QandATable.php" method="post">
  <th>Number of Questions:</th>
                <td class="spinner"><textarea class="spinnerQuestion" id="txtQuestion" name="txtQuestion" cols="2" rows="1"></textarea></td>
                <td><button class="scrollBtn" id="btnQuestionUp" type="button"><img src="Images/black_uppointing_triangle.png" alt="Increase" /></button>
                <button class="scrollBtn" id="btnQuestionDown" type="button"><img src="Images/black_downpointing_triangle.png" alt="Decrease" /></button></td>
                </tr>
                </table>
                <div id="numberAlert"></div>
                <p><input class="questionBtn" type="button" value="Prepare Questions" name="prequestion" onclick="myClickHandler()"/></p>      <!-- Prepare Questions here-->
    
        </form>


Below is code for the table (QandATable.php)

<table border=1 id="qandatbl" align:center;>
    <tr>
    <th class="col1">Question No</th>
    <th class="col2">Option Type</th>
    <th class="col1">Duration</th>
    <th class="col2">Weight(%)</th>
    <th class="col1">Answer</th>
    <th class="col2">Video</th>
    <th class="col1">Audio</th>
    <th class="col2">Image</th>
    </tr>
    <tr>
    <?php
    $spinnerCount =(int) $_POST['txtQuestion'];
if($spinnerCount > 0) {
   for($i = 1; $i <= $spinnetCount; $i++) {
     echo "<td class='qid'></td>";
   }
}
?>
    
    <td class="options"></td>
    <td class="duration"></td>
    <td class="weight"></td>
    <td class="answer"></td>
    <td class="video"></td>
    <td class="audio"></td>
    <td class="image"></td>
	</tr>
	</table>


Is This A Good Question/Topic? 0
  • +

Replies To: I keep getting undefined index error

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,428
  • Joined: 23-August 08

Re: I keep getting undefined index error

Posted 21 November 2011 - 07:42 PM

You have a typo here:

if($spinnerCount > 0) {
   for($i = 1; $i <= $spinnetCount;


What happens in your Javascript here:
onclick="myClickHandler()"
?

If you're actually performing a POST, it looks like that index should be getting set.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,041
  • Joined: 08-June 10

Re: I keep getting undefined index error

Posted 22 November 2011 - 06:21 AM

and another typo: <table border=1 id="qandatbl" align:center;> should be either <table border=1 id="qandatbl" align="center"> or <table border=1 id="qandatbl"> with
#qandatbl {
    text-align: center;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1