Edit row of MySQL database table using a PHP form

Posted on 2011-05-06
Last Modified: 2012-05-11
I'm trying to populate a form with data from a MySQL database table using PHP. So then the user can edit the the row of data. I thought the code below would do the trick but data is not being displayed on the form. Attached I have the partial form to give you guys an idea of what I'm doing.

<input name="title" type="text" value="<?php echo $mysession['title']? id="title" size="70" maxlength="75"/>

Open in new window


$id = $_GET['id'];

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryValidationTextField.css" rel="stylesheet" type="text/css" />


<p>BACK TO <a href="../../index.php">ACCOUNT PAGE</a>	</p>
<p><a href="../../logout.php">LOGOUT</a></p>
<form method="POST" action="modifyform.php" enctype="multipart/form-data">
<input type="hidden" name="id" id="id" value="<?php echo $id; ?>" />
  <table width="729" border="0">
    <td width="111" height="68"><div align="right"><span style="color: #F00">*</span>Title</div></td>
    <td width="4"><div align="center">:</div></td>
    <td width="600"><label for="title"></label>
      <span id="sprytextfield4">
      <input name="title" type="text" value="<?php echo $mysession['title']? id="title" size="70" maxlength="75"/>

Open in new window

Question by:genesisvh
    LVL 8

    Expert Comment

    I dont see any SQL statements here
    LVL 2

    Expert Comment

    In your example are you passing anything to the page like ?id=123
    If not then id isn't being set so no data will show up in the form field.

    Now I don't know if your just testing how to populate a form field but the previous posting is right. Where is your sql query?
    LVL 15

    Expert Comment

    by:Jagadishwor Dulal
    I hope you already have select query and fetched records and displaying in your form for edit.
    If not then first create your select query and fetch records which will display data in your form field but here I have seen

    <input name="title" type="text" value="<?php echo $mysession['title']? id="title" size="70" maxlength="75"/>

    Open in new window

    You are fetching data from $mysession['title'] is that correct? if so than you should have sql statement before the above line like:

    $query="SELECT title from yourtablename WHERE id=$id";
    $mysession=mysql_fetch_row($query); //if this is correct than there should not be error

    Open in new window


    Author Comment

    Ok so I really screwed up and got all the fields to show the results except one. I'm having trouble showing the data from a text area. This is what I have, how can I fix it.
    <td><label for="description"></label>
          <textarea name="description" cols="70" rows="25" value="<? echo $rows['description']; ?>" id="description"></textarea></td>

    Open in new window

    LVL 14

    Accepted Solution

    can you please try ;

    <td><label for="description"></label>
          <textarea name="description" cols="70" rows="25" id="description"><? echo $rows['description']; ?></textarea></td>

    Author Closing Comment


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now