echoing html form with db data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

echoing html form with db data

Post by kkonline »

The code executes but i donot get any data displayed which is extracted from db. all the fields are blank

Code: Select all

if($mode == '3') {
    $edit = "SELECT * FROM wow WHERE id = $page AND catid = $catid";

    $result = mysql_query($edit) or die (mysql_error());

    $row = mysql_fetch_array($result);

echo "
<br>
<form action='ew.php' method='POST'><div>
    <b>Name</b><br /><input type='text' name='name' value='{$row['contributed_by']}'><br /><br />
    <b>Title</b><br /><input type='text' name='title' value='{$row['title']}'><br /><br />
    <b>Content</b><br /><textarea name='content' cols='45' rows='10'>{$row['content']}</textarea><br /><br />
    <b>Tags</b><br /><input type='text' name='tags' value='{$row['tags']}'><br /><br />
    <b>Mood</b><br />";
echo "<select name='mood' style='width:100px;'>";
    echo "<option value='1'" . ($row['mood'] == 1 ? ' selected=\'selected\'' : '') . ">Happy</option>";
    echo "<option value='2'" . ($row['mood'] == 2 ? ' selected=\'selected\'' : '') . ">Sad</option>";
    echo "<option value='3'" . ($row['mood'] == 3 ? ' selected=\'selected\'' : '') . ">Anxious</option>";
    echo "<option value='4'" . ($row['mood'] == 4 ? ' selected=\'selected\'' : '') . ">Angry</option>";
    echo "<option value='5'" . ($row['mood'] == 5 ? ' selected=\'selected\'' : '') . ">Surprized</option>";
echo "</select><br /><br />";
   echo" <input type='hidden' name='id' value='{$page}' />
    <input type='hidden' name='catid' value='{$catid}'>
    <input type='submit' value='Edit' />
    </div>
    </form>";

}
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

$row = mysql_fetch_array($result);
echo '<pre>'.print_r($row, TRUE).'</pre>';
Whats the output ?
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post by kkonline »

anjanesh wrote:

Code: Select all

$row = mysql_fetch_array($result);
echo '<pre>'.print_r($row, TRUE).'</pre>';
Whats the output ?
Ya thanks; i was able to solve that, actually i was querying with catid=1 and in the db all the rows had catid=0 ....
Post Reply