Link to home
Start Free TrialLog in
Avatar of DS928
DS928Flag for United States of America

asked on

Data in table clumping into one column

The data in this table is going in one column instead of their own column.  Where in the code is this happening?  And how can I fix it?
// IF THERE IS A POST-METHOD REQUEST, INSERT OR UPDATE THE ROW
if (!empty($_POST))
{
    // IF THE ID IS ZERO, INSERT A NEW ROW
    if ($_POST['recordId'] == 0)
    {
        // ESCAPE THE DATA FOR USE IN THE QUERY
        //$recordCust = $mysqli->real_escape_string($_POST['recordCust']);
        $recordSite = $mysqli->real_escape_string($_POST['recordSite']);
		$recordUser = $mysqli->real_escape_string($_POST['recordUser']);
        $recordPass = $mysqli->real_escape_string($_POST['recordPass']);
		$recordDateAdded = $mysqli->real_escape_string($_POST['recordDateAdded']);
        
        // CREATE AND RUN THE INSERT QUERY, TEST FOR ERRORS
        $sql = "INSERT INTO records ( recordSite, recordUser, recordPass, recordDateAdded ) VALUES ( '$recordSite', '$recordUser', '$recordPass', '$recordDateAdded' )";
        if (!$res= $mysqli->query($sql))
        {
            $err
            = 'QUERY FAILURE:'
            . ' ERRNO: '
            . $mysqli->errno
            . ' ERROR: '
            . $mysqli->error
            . ' QUERY: '
            . $sql
            ;
            trigger_error($err, E_USER_ERROR);
        }
    }

    // IF THE ID IS NOT ZERO, UPDATE THE ROW
    else
    {
        // ESCAPE THE DATA FOR USE IN THE QUERY
        $recordId    = $mysqli->real_escape_string($_POST['recordId']);
        $recordSite = $mysqli->real_escape_string($_POST['recordSite']);
        $recordUser = $mysqli->real_escape_string($_POST['recordUser']);
		$recordPass    = $mysqli->real_escape_string($_POST['recordPass']);
        $recordDateAdded = $mysqli->real_escape_string($_POST['recordDateAdded']);
       

        // CREATE AND RUN THE UPDATE QUERY, TEST FOR ERRORS
        $sql = "UPDATE records SET recordSite  = '$recordSite', recordUser  = '$recordUser', recordPass = '$recordPass', recordDateAdded = '$recordDateAdded' WHERE recordId = $recordId LIMIT 1";
        if (!$res= $mysqli->query($sql))
        {
            $err
            = 'QUERY FAILURE:'
            . ' ERRNO: '
            . $mysqli->errno
            . ' ERROR: '
            . $mysqli->error
            . ' QUERY: '
            . $sql
            ;
            trigger_error($err, E_USER_ERROR);
        }
    }
} // END OF POST-METHOD PROCESSING


// IF THERE IS AN ID IN THE GET-METHOD REQUEST GET THE RECORD
$recordId = !empty($_GET['recordId']) ? (int)$_GET['recordId'] : 0;
if ($recordId)
{
    $sql = "SELECT recordSite, recordUser, recordPass, recordDateAdded FROM records WHERE recordId = $recordId LIMIT 1";
    if (!$res= $mysqli->query($sql))
    {
        $err
        = 'QUERY FAILURE:'
        . ' ERRNO: '
        . $mysqli->errno
        . ' ERROR: '
        . $mysqli->error
        . ' QUERY: '
        . $sql
        ;
        trigger_error($err, E_USER_ERROR);
    }

    // THERE WILL ONLY BE ONE ROW (AT MOST) BECAUSE OF LIMIT CLAUSE
    $row = $res->fetch_object();
    if ($row)
    {
        $recordSite = $row->recordSite;
        $recordUser = $row->recordUser;
		$recordPass = $row->recordPass;
        $recordDateAdded = $row->recordDateAdded;
    }
}

// CREATING A QUERY TO LIST THE TEST DATA ALPHABETICALLY
$sql = "SELECT recordId, recordSite, recordUser, recordPass, recordDateAdded FROM records ORDER BY recordId, recordDateAdded";
if (!$res= $mysqli->query($sql))
{
    $err
    = 'QUERY FAILURE:'
    . ' ERRNO: '
    . $mysqli->errno
    . ' ERROR: '
    . $mysqli->error
    . ' QUERY: '
    . $sql
    ;
    trigger_error($err, E_USER_ERROR);
}

// OUR WEB PAGE WILL BE CREATED IN THIS VARIABLE
$out = NULL;

// IF THERE IS A CURRENT UPDATE CREATE THE "UPDATE" FORM
if ($recordId)
{
    $out = <<<EOD
<form method="post" action="RAY_EE_table_maintenance_form.php">
<input type="hidden" name="recordId" value="$recordId" />
EOD;
}

// PRINT OUT THE ROWS OF THE TABLE WITH UPDATE / DELETE LINKS
$out .= '<table class="CSSTableGenerator">' . PHP_EOL;
 				$out .= '<tr>'
                .'<th>Action</th>'
				.'<th>Site</th>'
                .'<th>User Name</th>'
				.'<th>Password</th>'
                .'<th>Date Added</th>'
			    . '</tr>';
while ($row = $res->fetch_object())
{
    $out .= '<tr>'
    . '<td>'
    . '[<a href="RAY_EE_table_maintenance_form.php?recordId='
    . $row->recordId
    . '">update</a>]'
    . '[<a href="RAY_EE_table_maintenance_delete.php?recordId='
    . $row->recordId
    . '">delete</a>]'
    . '</td>'
    . '<td>'
    ;

    // IF THIS IS TO BE UPDATED
    if ($row->recordId == $recordId)
    {
        $out .= '<input name="recordSite" value="' . $recordSite . '" />';
        $out .= '<input name="recordUser" value="' . $recordUser . '" />';
		$out .= '<input name="recordPass" value="' . $recordPass . '" />';
        $out .= '<input name="recordDateAdded" value="' . $recordDateAdded . '" />';
		
        $out .= '<input type="submit" name="signal" value="Update" />';
    }
    else
    {
        $out .= "$row->recordSite $row->recordUser $row->recordPass $row->recordDateAdded";
    }
    $out .= '</td>'
    . '</tr>'
    . PHP_EOL
    ;
}
$out .= '</table>' . PHP_EOL;
if ($recordId) $out .= '</form>'  . PHP_EOL;

// PUT THE "ADD NEW" TABLE AT THE END (CRUD "CREATE")
$out .= <<<EOD
 &nbsp;<br>
  &nbsp;<br>
   &nbsp;<br>
<form method="post" action="RAY_EE_table_maintenance_form.php">
Add new information
<input type="hidden" name="recordId" value="0" />
<br>recordSite: <input name="recordSite" placeholder="Site" />
<br>recordUser: <input name="recordUser" placeholder="User"  />
<br>recordPass: <input name="recordPass" placeholder="Password" />
<br>recordDateAdded: <input name="recordDateAdded" placeholder="Date Added"  />
<br><input type="submit" name="signal" value="Add" />
</form>
EOD;

echo $out;

Open in new window

Avatar of DS928
DS928
Flag of United States of America image

ASKER

I might be mistaken but I think it lies in here...?
<form method="post" action="RAY_EE_table_maintenance_form.php">
<input type="hidden" name="recordId" value="$recordId" />
EOD;
}

// PRINT OUT THE ROWS OF THE TABLE WITH UPDATE / DELETE LINKS
$out .= '<table class="CSSTableGenerator">' . PHP_EOL;
 				$out .= '<tr>'
                .'<th>Action</th>'
				.'<th>Site</th>'
                .'<th>User Name</th>'
				.'<th>Password</th>'
                .'<th>Date Added</th>'
			    . '</tr>';
while ($row = $res->fetch_object())
{
    $out .= '<tr>'
    . '<td>'
    . '[<a href="RAY_EE_table_maintenance_form.php?recordId='
    . $row->recordId
    . '">update</a>]'
    . '[<a href="RAY_EE_table_maintenance_delete.php?recordId='
    . $row->recordId
    . '">delete</a>]'
    . '</td>'
    . '<td>'
    ;

    // IF THIS IS TO BE UPDATED
    if ($row->recordId == $recordId)
    {
        $out .= '<input name="recordSite" value="' . $recordSite . '" />';
        $out .= '<input name="recordUser" value="' . $recordUser . '" />';
		$out .= '<input name="recordPass" value="' . $recordPass . '" />';
        $out .= '<input name="recordDateAdded" value="' . $recordDateAdded . '" />';
		
        $out .= '<input type="submit" name="signal" value="Update" />';
    }
    else
    {
        $out .= "$row->recordSite $row->recordUser $row->recordPass $row->recordDateAdded";
    }
    $out .= '</td>'
    . '</tr>'
    . PHP_EOL
    ;
}
$out .= '</table>' . PHP_EOL;
if ($recordId) $out .= '</form>'  . PHP_EOL;

Open in new window

change line 139 of your code from -
    <td>

to

    </tr>
Avatar of DS928

ASKER

Didn't work.
Avatar of DS928

ASKER

Its in here...I think the outs all have to be made seperate as opposed to being in on <td>
$out .= '<table class="CSSTableGenerator">' . PHP_EOL;
 				$out .= '<tr>'
                .'<th>Action</th>'
				.'<th>Site</th>'
                .'<th>User Name</th>'
				.'<th>Password</th>'
                .'<th>Date Added</th>'
			    . '</tr>';
while ($row = $res->fetch_object())
{
    $out .= '<tr>'
    . '<td>'
    . '[<a href="RAY_EE_table_maintenance_form.php?recordId='
    . $row->recordId
    . '">update</a>]'
    . '[<a href="RAY_EE_table_maintenance_delete.php?recordId='
    . $row->recordId
    . '">delete</a>]'
    . '</td>'
    . '<td>'
    ;

    // IF THIS IS TO BE UPDATED
    if ($row->recordId == $recordId)
    {
        $out .= '<input name="recordSite" value="' . $recordSite . '" />';
		$out .= '<input name="recordUser" value="' . $recordUser . '" />';
		$out .= '<input name="recordPass" value="' . $recordPass . '" />';
        $out .= '<input name="recordDateAdded" value="' . $recordDateAdded . '" />';
		$out .= '<input type="submit" name="signal" value="Update" />';
    }
    else
    {
        $out .= "$row->recordSite";
		$out .= "$row->recordUser";
		$out .= "$row->recordPass";
		$out .= "$row->recordDateAdded";
    }
    $out .= '</td>'
    . '</tr>'
    . PHP_EOL
    ;
}
$out .= '</table>' . PHP_EOL;

Open in new window

By "column" do you mean the HTML document or the columns of the database?
Avatar of DS928

ASKER

Hello Ray.  This is code that you sent me that I am modifying.  If you go to this link you will see that the headers are all there but the info is bunched into one column.

http://www.mediascrubber.com/RAY_EE_table_maintenance_form.php
I'm not sure that I'm reading this correctly, but here is something that looks "interesting"... Consider this block of code.  It creates five columns of the HTML table
$out .= '<tr>'
     . '<th>Action</th>'
     . '<th>Site</th>'
     . '<th>User Name</th>'
     . '<th>Password</th>'
     . '<th>Date Added</th>'
     . '</tr>'
     . PHP_EOL
     ;

Open in new window

Now just below it we have this block of code.  If you count the <td> tags here, you see a mismatch with the five <th> tags.
while ($row = $res->fetch_object())
{
    $out .= '<tr>'
    . '<td>'
    . '[<a href="RAY_EE_table_maintenance_form.php?recordId='
    . $row->recordId
    . '">update</a>]'
    . '[<a href="RAY_EE_table_maintenance_delete.php?recordId='
    . $row->recordId
    . '">delete</a>]'
    . '</td>'
    . '<td>'
    ;

    // IF THIS IS TO BE UPDATED
    if ($row->recordId == $recordId)
    {
        $out .= '<input name="recordSite" value="' . $recordSite . '" />';
        $out .= '<input name="recordUser" value="' . $recordUser . '" />';
        $out .= '<input name="recordPass" value="' . $recordPass . '" />';
        $out .= '<input name="recordDateAdded" value="' . $recordDateAdded . '" />';
        
        $out .= '<input type="submit" name="signal" value="Update" />';
    }
    else
    {
        $out .= "$row->recordSite $row->recordUser $row->recordPass $row->recordDateAdded";
    }
    $out .= '</td>'
    . '</tr>'
    . PHP_EOL
    ;
}

Open in new window

HTML tables are not really suitable for applications like this where you want to format data, but you're not using tabular data structures.  You might consider wrapping these data elements in <span> or <div> or <li> tags.  You can assign names to the tags and use CSS to apply relative or explicit positioning to the data elements.  The clue to know when you're not using tabular data appears when you see that the number of header columns and the number of data columns are not the same.
Our posts crossed in cyberspace.  Now that I see the generated HTML source, I am almost sure it has to do with the difference in the number of HTML table columns.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America 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
ALSO on this line -
     $out .= '<input type="submit" name="signal" value="Update" /></td>';

I can not see WHY this is in here, as far as I can Tell there is no <form> for this <table> to have a submit input for, AND as far as I can tell there may be some confusion with your first column links as "[update]"  what is that about?

And Also your page code lacks very necessary elements such as the closing </head> tag AND the <body> tag, You have these -

<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/easyResponsiveTabs.js" type="text/javascript"></script>
<script src="js/script.js"></script>

and yet I see NO javascript at all in your page code.
Avatar of DS928

ASKER

It worked! Thank you.