Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a php input form with uneditable fields populated from another table 1

Status
Not open for further replies.
Mar 23, 2015
37
US
I have a donation list page that displays data from the donation and donor tables. I put a record edit link on each row and on the record edit page where I know have the donor_id I'd like to display the donor name (stored in the donor table) associated with that donation record but have it locked so the user can't change that information on that page.

Code right now...
Code:
   <?php 
    $id = $_GET['id'];
	$sql = "SELECT * FROM donations WHERE donor_id = '$id'";
	$result = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_array($result);

//Extract fields.
  $donor_id=$_POST['donor_id'];
  $date=$_POST['date'];
  $amount=$_POST['amount'];
  $donation_cat=$_POST['donation_cat'];
  $miscellaneous=$_POST['miscellaneous'];
  $note=$_POST['note'];
	
  ?>
  
   <h1>Donation Details</h1>
   <div class="table-sortable:default">
   <p style="margin-left:25px;"> Edit Donation Record</p>
<form action="updateDonation.php" method="post">
<input type="hidden" name="id" value="<? echo $id ?>" />
<table>
 <tr><td>Donor: </td></td><td><input type="text" name="donor_id" value="<?php echo $row['donor_id']; ?>"></td></tr>
 <tr><td>Date: </td></td><td><input type="text" name="date" value="<?php echo $row['date']; ?>"></td></tr>
 <tr><td>Value: </td></td><td><input type="text" name="amount" value="<?php echo $row['amount']; ?>"></td></tr>
 <tr><td>Catagory: </td></td><td><input type="text" name="donation_cat" value="<?php echo $row['donation_cat']; ?>"></td></tr>
 <tr><td>Item: </td><td><input type="text" name="miscellaneous" value="<?php echo $row['miscellaneous']; ?>"></td></tr>
 <tr><td>Note:  </td><td><input type="text" name="note" value="<?php echo $row['note']; ?>"></td></tr>
</table>
<p style="margin-left:25px;"><input type="submit"></p>
</form>

Yes I know I'm using an older code version. Switching in the middle of this project will confuse me even further. Once everything is working I'll start learning the new stuff and rewrite the code and it will make more sense to me.

Thanks!
 
I'm not sure there is a question in there.

It looks like you know how to pull information from the database, and echo it out.

To make it non-editable, just don't put it in an input box. Yes, you can make input fields "read-only" - but that also exposes an additional field POST/GET field unnecessarily.

Otherwise you have two options, mark it as readonly or disabled.

HTML:
<input type="text" value="This Value" readonly="readonly" />
<input type="text" value="This Value" disabled="disabled" />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top