Hi guys! I have a script which use foreach to output value from database to textfield and textarea.However something went wrong in the script that cause missing of textfield and textarea.Can you guys help to pinout the error?Thanks..

<?php
include ('dbconn.cfg');// database configuration file
$connection = @mysql_connect("localhost", "root", "") or die("Cannot connect to server!");
?>

        <html>
        <title></title>
        <head>
        <body>
        <h2><center>Member Profile</center></h2>
        <table border = '1'  cellpadding = '3' cellspacing = '2' style = 'background-color: #ADD8E6'>
        <tr>
        <th>Full Name</th>
        <th>Telephone</th>
        <th>Address</th>
        </tr>
		<tr>

		<?

if (isset($_SESSION['gmembername']))
{
    $tbl_name = "member";
    $sql = "SELECT name,telephone,address FROM $tbl_name";

$result = @mysql_query($sql, $connection) or die("Cannot execute query.");
$numrow = mysql_num_rows($result);

if ($numrow != 0)
{// fetch each record in result set
    for ($counter = 0; $row = mysql_fetch_row($result); $counter++)
    {
        foreach ($row as $key => $value)
        {
            if ($key == 0 && $key == 1)
            {
?>
                 <td><input type ="text" size = "30" value = "<?php
                    echo $value; ?>" readonly = "readonly"></td>
                 <?php
                }
                else
                {
                    if ($row == 2)
                    {
?>                 
<td><textarea rows = "3"><?php echo $value; ?></textarea></td> <?php } } } } } } ?> </tr> </table> <table> <tr> <td>&nbsp;</td> <td width='4%'>&nbsp;</td> <td></tr> <tr> <td>&nbsp;</td> <td width='4%'>&nbsp;</td> <td><input type='submit' name='submit' value='Upgrade'></td> </table> </body> </head> </html>

    You need || instead of && the way you have it will never be true.

    Also you need to put $row[] = mysql_fetch... in the for loop

      HalfaBee wrote:

      You need || instead of && the way you have it will never be true.

      Also you need to put $row[] = mysql_fetch... in the for loop

      Thanks...🙂 it is worked when I remove else if and change && to ||.I doesn't put $row[] though only work in mysql_fetch_array()

        HalfaBee wrote:

        You need || instead of && the way you have it will never be true.

        Also you need to put $row[] = mysql_fetch... in the for loop

        Thanks...🙂 it is worked when I remove else if and change && to ||.I doesn't put $row[] though only work in mysql_fetch_array()

          Sorry my mistake, I misread what you were doing.

          At least one comment was correct. 🙂

            Write a Reply...