Jump to content

Passing variables


alewis

Recommended Posts

The code below is a form the gets information from a database and post it into the appropriate field. I am having a problem with the while loop. All the variables before the while loop work just great and echo out how they should. But everything after the while loop does not work. I know it has something to do with the while loop because when I take the while loop out everything works as it should. Can anyone please help me with this?

 

  <? $id = $_POST["id"];
  $therapy = $_POST["therapy"];
  db_connect();
  $query=mysql_query("select * from student where student_id = $id") or die ("invalid query");
  $row=mysql_fetch_array($query);

print "<table width='330' border=0 align='center'>
  <form method='POST' action='table.php'>
    <td>*First Name:</td>
    <td>*Last Name:</td>
    <tr>";
?>
      <td width="157"><input size="23" name="first_name" value="<?php echo "$row[first_name]"; ?>" /></td>
      <td width="138"><input type="text" size="23" name="surname" value="<?php echo "$row[surname]"; ?>" /></td>
    </tr>
    <tr>
    <td>Level:</td>
     <td>Therapy:</td>
      
    </tr>
    <tr>
      <td>
      <select name="program_level">
        <option <?php if ($row[program_level]=='1') echo "selected=yes";  ?> value="1">O&A</option>
        <option <?php if ($row[program_level]=='2') echo "selected=yes";  ?> value="2">Student</option>
        <option <?php if ($row[program_level]=='3') echo "selected=yes";  ?> value="3">Supervisor</option>
        <option <?php if ($row[program_level]=='4') echo "selected=yes";  ?> value="4">Manager</option>
        <option <?php if ($row[program_level]=='5') echo "selected=yes";  ?> value="5">Director</option>
        <option <?php if ($row[program_level]=='6') echo "selected=yes";  ?> value="6">Graduate</option>
        </select>
      </td>
            <td>


<!-- Auto drop down for therapist names-->  
         
<? $query2=mysql_query("select * from therapy_info;"); ?>

<select name='therapy'>

<? while ($row=mysql_fetch_assoc($query2)){ ?>

<option value="<? echo "$row[therapy_name]"; ?>"> <? echo "$row[therapy_name]"; } ?> </option>

</select>

<!-- End Auto drop down for therapist names-->



</td> 
   </tr>
    <tr>
      <td>Active:<?php echo "$row[active]"; ?></td>
    </tr>
    <tr>
      <td><select name='active' value='$row[active]'>
        <option <?php if ($row[active]=='1') echo "selected=yes";  ?> value='1'>Active</option>
        <option <?php if ($row[active]=='0') echo "selected=yes";  ?> value='0'>Inactive</option>
        </select>
        </td>
    </tr>
    <?php 
    print "<tr>
      <td><input type='submit' value='Change' name='button' /></td>
      <input type='hidden' name='id' value='$id' />";
  ?>
      <input type='hidden' name='$hardcode_session' />
      <?

      
    print "</tr>
  </form>
</table>";

Link to comment
https://forums.phpfreaks.com/topic/220293-passing-variables/
Share on other sites

Don't use short <? tags.

 

Variables don't need to be surrounded by quotes, array index do. This...

 

<?php echo "$row[first_name]"; ?>

 

Should be....

 

<?php echo $row['first_name']; ?>

 

I don't see any closing } barace for that while loop.

 

Thank you, the closing } brace is

<option value="<? echo $row[therapy_name]; ?>"> <? echo $row[therapy_name]; } ?> </option>

and I tried what you said but I still am not getting the variables to show up after the while loop.

Link to comment
https://forums.phpfreaks.com/topic/220293-passing-variables/#findComment-1141579
Share on other sites

There's a form field with no type= attribute. May or may not be causing a rendering problem . . .

<td width="157"><input size="23" name="first_name" value="<?php echo "$row[first_name]"; ?>" /></td>

 

You did change all of the short open <? tags to full <?php syntax, and that didn't make a difference?

 

 

Link to comment
https://forums.phpfreaks.com/topic/220293-passing-variables/#findComment-1141583
Share on other sites

There's a form field with no type= attribute. May or may not be causing a rendering problem . . .

<td width="157"><input size="23" name="first_name" value="<?php echo "$row[first_name]"; ?>" /></td>

 

You did change all of the short open <? tags to full <?php syntax, and that didn't make a difference?

 

I fixed that type=text and yes I changed all the <? to <?php and still nothing. It really is right down to where my while loop is. If I put anything after my while loop it stops working but one line before I actually right while it works fine?

Link to comment
https://forums.phpfreaks.com/topic/220293-passing-variables/#findComment-1141586
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.