Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: form question

  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts

    form question

    Is there a mistake with this form - when a user select the project from the drop down the year should show up accordingly to the project selected but I get this result:

    Code:
    9<br /> <b>Notice</b>:  Undefined index: year in <b>C:\wamp\www\project\0_insert.php</b> on line <b>72</b><br />
    from the Year field.

    PHP Code:
    <form id="form1" name="form1" method="post" action="">
      <table border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Project:</td>
          <td><label>
            <select name="project" id="project">
              <?php
    do {  
    ?>
              <option value="<?php echo $row_Recordset1['acr_id']?>"><?php echo $row_Recordset1['project']?></option>
              <?php
    } while ($row_Recordset1 mysql_fetch_assoc($Recordset1));
      
    $rows mysql_num_rows($Recordset1);
      if(
    $rows 0) {
          
    mysql_data_seek($Recordset10);
          
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
      }
    ?>
            </select>
          </label></td>
          <td>Year:</td>
          <td><label>
            <input name="year" type="text" id="year" value="<?php echo $row_Recordset1['acr_id']?><?php echo $row_Recordset1['year']; ?>" />
          </label></td>
        </tr>
    Thanks in advanced.

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    is this the 0_insert.php file?

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by seco View Post
    is this the 0_insert.php file?
    yes it is. the project session of the form supposed to be dynamically populated when the user select the project. then they will type in other infos in other fields before summiting the form.

    Thanks.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Where is your $Recordset1 query? Do you have a column in you db table called year? Also in your select are you calling that column from your table? If you aren't then you will get the index notice.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Where is your $Recordset1 query? Do you have a column in you db table called year? Also in your select are you calling that column from your table? If you aren't then you will get the index notice.
    Code:
    SELECT *
    FROM admin_project
    ORDER BY project ASC
    Yes, there is a 'year' col. in the table. Now the year did show out. But I just cannot make it sync with the selected project from the drop down menu. Thanks.
    Last edited by pphpnewbie; 01-23-2010 at 11:05 AM.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by pphpnewbie View Post
    Code:
    SELECT *
    FROM admin_project
    ORDER BY project ASC
    Yes, there is a 'year' col. in the table. Now the year did show out. But I just cannot make it sync with the selected project from the drop down menu. Thanks.
    you need to have the option like this:
    Code:
    <option value="year_value" selected="selected">year_value</option>
    this for xhtml, your question is in fact a html/css question,

    best regards

  • #7
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <option value="year_value" selected="selected">year_value</option>
    Thanks. Would you kindly show me where to insert that code in my form:
    Code:
    <form id="form1" name="form1" method="post" action="">
      <table border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Project:</td>
          <td><label>
            <select name="project" id="project">
              <?php
    do {  
    ?>
              <option value="<?php echo $row_Recordset1['acr_id']?>"><?php echo $row_Recordset1['project']?></option>
              <?php
    } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
      $rows = mysql_num_rows($Recordset1);
      if($rows > 0) {
          mysql_data_seek($Recordset1, 0);
    	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      }
    ?>
            </select>
          </label></td>
          <td>Year:</td>
          <td><label>
            <input name="year" type="text" id="year" value="<?php echo $row_Recordset1['year']; ?>" />
          </label></td>
        </tr>
    Thanks

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by pphpnewbie View Post
    Code:
    <option value="year_value" selected="selected">year_value</option>
    Thanks. Would you kindly show me where to insert that code in my form:
    Code:
    <form id="form1" name="form1" method="post" action="">
      <table border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>Project:</td>
          <td><label>
            <select name="project" id="project">
              <?php
    do {  
    ?>
              <option value="<?php echo $row_Recordset1['acr_id']?>"><?php echo $row_Recordset1['project']?></option>
              <?php
    } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
      $rows = mysql_num_rows($Recordset1);
      if($rows > 0) {
          mysql_data_seek($Recordset1, 0);
    	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      }
    ?>
            </select>
          </label></td>
          <td>Year:</td>
          <td><label>
            <input name="year" type="text" id="year" value="<?php echo $row_Recordset1['year']; ?>" />
          </label></td>
        </tr>
    Thanks
    why do you use a do-while when you need a while? $row_Recordset1['acr_id'] and $row_Recordset1['project'] are undefined until you fetch them using $row_Recordset1 = mysql_fetch_assoc($Recordset1).

    PHP Code:
    while($row_Recordset1 mysql_fetch_assoc($Recordset1)){
       print 
    '          <option value="';
       print 
    $row_Recordset1['acr_id'];
       print 
    '"';
       if(.....){ 
    // I don't know what field from $row_Recordset1 and what variable to compare here, change this to what you know you need
          
    print ' selected="selected"';
       }
       print 
    '>'$row_Recordset1['project'] . '</option>';

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •