xstevey_bx Posted July 6, 2008 Share Posted July 6, 2008 $query = "SELECT * FROM users WHERE id=$id"; $result = mysql_query($query); $num = mysql_num_rows($result); $row = mysql_fetch_array ($result, MYSQL_NUM); if ($num == 1) { echo '<h3>Edit User</h3><form action="?id=news_comment_edit&num='.$id.'" method="post">'; $arr = array('id', 'username', 'password', 'email', 'forename', 'surname', 'country', 'state', 'postcode', 'dob', 'gender', 'registrationdate', 'lastlogin', 'code', 'activated'); foreach ($arr as $value) { echo '<p>'.$value.' : <input type="text" name="'.$value.'" size="25" maxlength="255" value="'. $row[{$value}] .'" /></p><br/>'; } unset($value); } This is a snippet from a code from an edit information page. Im trying to build a form from a list of MySQL column names stored in an array. The problem is in the line echo '<p>'.$value.' : <input type="text" name="'.$value.'" size="25" maxlength="255" value="'. $row[{$value}] .'" /></p><br/>'; I want the $row[{$value}] to show the information stored in the $row = mysql_fetch_array depending on what the $value in the foreach loop is Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 6, 2008 Share Posted July 6, 2008 change $row[{$value}] to $row[$value] Scott. Quote Link to comment Share on other sites More sharing options...
trq Posted July 6, 2008 Share Posted July 6, 2008 Your not returning an associative array from mysql_fetch_array(). Either use mysql_fetch_assoc() (recommended) instead or use the MYSQL_ASSOC constant. eg; $row = mysql_fetch_array ($result, MYSQL_ASSOC); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.