Using & Passing Textbox Array Values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Using & Passing Textbox Array Values

Post by TNIDBMNG »

I'm creating a schedule which links to a MySQL database. I have the code looping through the table and listing any schedules assigned to a specific employee. I have a notes column which lists any notes for a specific duty. After all the notes are listed I have a text box where the employee can enter a new note for that duty. I want this textbox to be part of an array and I want to use the ID of the duty to specify which textbox it is referring to. Next to the text box I have a link which will pass that new note to the new page. My code isn't working so I was wondering if someone could look at it and tell me what's wrong.

Code: Select all

<?php
echo '<td width="40%">' .$strnotes.'<input type="Text" name=txtNote['.$id.'] size="70%">&nbsp;<a href=itschedule_edit.php?priority='.$id.'&note=txtNote['.$id.'] >Insert</a>&nbsp;</td>';
?>
Or if anyone knows of an easier way of doing this if they could please let me know, I'm just learing PHP.

Thanks in advance.


feyd | Moved from Tutorial section
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post the rest of your code please.
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Post by TNIDBMNG »

Code: Select all

<?php
include("include/header_admin.php");
include("include/dbconnect.php");

echo '<h1 align="center";><font color="#000099">Daily IT Schedule</font></h1>';
echo '<br>';
	
$cook=$_COOKIE["logged_in"];
$validation=$cook[success];
$user_id=$cook[user_id];

mysql_selectdb("tni_secure", $cnx);
	
$sql=("SELECT CONCAT(firstName, ' ', lastName) AS name from tblUser where ID='" . $user_id ."';");
$result=mysql_query($sql,$cnx);
$row = mysql_fetch_row($result);

echo '<font size="3" color="#000000">';
echo '<table width="100%">';
echo '<tr><td width="15%"><div align="left">Employee Name: </div></td>';
echo '<td width="40%">' . $row[0] . '</td>';
echo '<td width="45%"><div align="left">' . date("l:F j, Y") . '</div></td>';
echo '</tr>';
echo '</table>';

$sql="SELECT DISTINCT tblCategory.ID AS categoryID, tblCategory.category ";
$sql=$sql."FROM tblITPriorities LEFT JOIN tblCategory ON tblITPriorities.categoryID = ";
$sql=$sql."tblCategory.ID WHERE (((tblITPriorities.assignedTo)='". $user_id . "'));";
	
$result=mysql_query($sql,$cnx);
	
$num_rows = mysql_num_rows($result);
$count=0;

while ($count<$num_rows){
   $category=mysql_result($result,$count,"category");
   $categoryid=mysql_result($result,$count,"categoryID");
	
   echo '<font size="2">';
   echo '<table width="100%" border="0" bordercolor="#000000" bgcolor="#000000">';
   echo '<tr bgcolor="#6699FF"><td width="10%" height="21" bordercolor="#000000">Date</td>';
   echo '<td width="25%">' .$category. '</td>';
   echo '<td width="40%">Notes</td>';
   echo '<td width="10%">Status</td>';
   echo '<td width="5%">Completed</td>';
   echo '<td width="10%">Date Completed</td>';
   echo '</tr>';
		
   $sql2="SELECT tblITPriorities.ID, tblITPriorities.categoryID, tblITPriorities.description, ";
   $sql2=$sql2."tblITPriorities.percentComplete, tblITPriorities.completed, tblITPriorities.assignedTo, ";
   $sql2=$sql2."date_format(tblITPriorities.date,'%d-%b-%Y') as startdate, date_format(tblITPriorities.dateCompleted,'%d-%b-%Y') as enddate ";
   $sql2=$sql2."FROM tblITPriorities ";
   $sql2=$sql2."WHERE (((tblITPriorities.categoryID)='". $categoryid . "') AND ";
   $sql2=$sql2."((tblITPriorities.assignedTo)='". $user_id . "'));";
	
   $result2=mysql_query($sql2,$cnx);
	
   $num_rows2 = mysql_num_rows($result2);
   $count2=0;
		
   while ($count2<$num_rows2){
      $id=mysql_result($result2,$count2,"ID");
      $categoryid=mysql_result($result2,$count2,"categoryID");
      $description=mysql_result($result2,$count2,"description");
      $percentcomplete=mysql_result($result2,$count2,"percentComplete");
      $completed=mysql_result($result2,$count2,"completed");
      $assignedTo=mysql_result($result2,$count2,"assignedTo");
      $date=mysql_result($result2,$count2,"startdate");
      $datecompleted=mysql_result($result2,$count2,"enddate");
			
      $sql3="SELECT * from tblITNotes WHERE ((tblITNotes.itPriorityID)='". $id . "');";
      $result3=mysql_query($sql3,$cnx);
      $num_rows3 = mysql_num_rows($result3);
      $count3=0;
			
      while ($count3<$num_rows3){
         $notes=mysql_result($result3,$count3,"notes");
         if ($count3==0){
            $strnotes = "1. ".$notes."&nbsp;<a href=itschedule_edit.php?priority='.$id.'&note=txtNote['.$id.'].value >Edit</a>&nbsp;<br>";
         } else {
             $strnotes = $strnotes.($count3+1).". ".$notes."&nbsp;<a href=itschedule_edit.php?priority='.$id.'&note=txtNote['.$id.'].value >Edit</a>&nbsp;<br>";
         }
         $count3++;
       }
			
      echo '<tr bgcolor="#FFFFFF"><td width="10%" bordercolor="#000000" >'. $date. '</td>';
      echo ("<td><a href='itschedule_edit.php?priority=".$id."'>".$description. "</a>");
      echo '<td width="40%">' .$strnotes.'<input type="Text" name=txtNote['.$id.'] size="70%">&nbsp;<a href=itschedule_edit.php?priority='.$id.'&note=txtNote['.$id.'] >Insert</a>&nbsp;</td>';
      echo '<td width="10%" align="center">' .$percentComplete. '%</td>';
      echo '<td width="5%" align="center">' .$Completed. '</td>';
      echo '<td width="10%">' .$datecompleted. '</td>';
      echo '</tr>';
      $count2++;
   }
   $count++;
}
	
echo '</table>';
echo '</font>';
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

while ($count3<$num_rows3){
         $notes=mysql_result($result3,$count3,"notes");
         if ($count3==0){
            $strnotes = "1. ".$notes." <a href=itschedule_edit.php?priority='.$id.'&note=txtNote['.$id.'].value >Edit</a> <br>";
         } else {
             $strnotes = $strnotes.($count3+1).". ".$notes." <a href=itschedule_edit.php?priority='.$id.'&note=txtNote['.$id.'].value >Edit</a> <br>";
         }
         $count3++;
       }
will have some problems.. you'll actually get unexpected $_GET params in itshedule_edit.php of $_GET['note'] = 'txtNote[X].value'

A form is never started in this code either, so there's no where to send the data.. your "insert" links don't submit this form, so the actual data isn't getting passed anywhere..
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Post by TNIDBMNG »

I'm sorry I forgot that part was in there, I know that won't work. I was wondering about the line that I originally posted. On the line

Code: Select all

<?php
echo '<td width="40%">' .$strnotes.'<input type="Text" name=txtNote['.$id.'] size="70%">&nbsp;<a href=itschedule_edit.php?priority='.$id.'&note=txtNote['.$id.'] >Insert</a>&nbsp;</td>';
?>
the ID passes to the next page fine but note passes as txtNote[2] if ID is 2. I need it to pass the value in the textbox not the name of the text box. Do I need to use a form? If I do how would I get it so when the Insert link is clicked it sends the value of the specific textbox to the next page?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'll need javascript to pull that data out, adding it to the page's actual form in a hidden field, along with the id number in a seperate hidden field and submit that to itschedule_edit.php
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Post by TNIDBMNG »

I'm pretty new to PHP and Javascript can you point me in the right direction?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

untested example

Code: Select all

function insertNote(id)
&#123;
  document.forms&#1111;'your_real_form''s_name'].elements&#1111;'note'].value = document.getElementByName ? document.getElementByName( 'txtNote&#1111;' + id + ']' ).value : document.all&#1111; 'txtNote&#1111;' + id + ']' ].value;
  document.forms&#1111;'your_real_form''s_name'].elements&#1111;'id'].value = id;
  document.forms&#1111;'your_real_form''s_name'].submit();
&#125;

--------------

<a href="javascript:insertNote(' . $id . ')" title="Insert">Insert</a>
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Post by TNIDBMNG »

Thanks so much for getting me started. I'm going to through this into my code tomorrow and work on it from there. Thanks again.
Post Reply