Link to home
Start Free TrialLog in
Avatar of genesisvh
genesisvh

asked on

Edit row of MySQL database table using a PHP form

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

<?php
session_start();
$_SESSION['id'];
$_SESSION['$myusername'];

$id = $_GET['id'];

?>
<head>
<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" />
</head>

<body>

<p>BACK TO <a href="../../index.php">ACCOUNT PAGE</a>	</p>
<p><a href="../../logout.php">LOGOUT</a></p>
<p>USE THIS FORM TO POST!</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">
  <tr>
    <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

Avatar of PranjalShah
PranjalShah
Flag of United States of America image

I dont see any SQL statements here
Avatar of chemdry
chemdry

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?
Avatar of 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

Avatar of genesisvh

ASKER

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>
  </tr>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ali Kayahan
Ali Kayahan
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks