Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Edit row of MySQL database table using a PHP form

Posted on 2011-05-06
6
Medium Priority
?
495 Views
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

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

0
Comment
Question by:genesisvh
6 Comments
 
LVL 8

Expert Comment

by:PranjalShah
ID: 35710474
I dont see any SQL statements here
0
 
LVL 2

Expert Comment

by:chemdry
ID: 35710554
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?
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 35710858
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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:genesisvh
ID: 35710895
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

0
 
LVL 14

Accepted Solution

by:
Ali Kayahan earned 2000 total points
ID: 35711736
can you please try ;

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

Author Closing Comment

by:genesisvh
ID: 35712077
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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