Solved

Data in table clumping into one column

Posted on 2015-01-27
11
76 Views
Last Modified: 2015-01-27
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

0
Comment
Question by:DS928
  • 5
  • 3
  • 3
11 Comments
 

Author Comment

by:DS928
ID: 40573216
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

0
 
LVL 33

Expert Comment

by:Slick812
ID: 40573379
change line 139 of your code from -
    <td>

to

    </tr>
0
 

Author Comment

by:DS928
ID: 40573727
Didn't work.
0
 

Author Comment

by:DS928
ID: 40574025
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

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40574208
By "column" do you mean the HTML document or the columns of the database?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:DS928
ID: 40574216
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
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40574232
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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40574237
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.
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 40574254
You have such mixed up Output, it's difficult to get what you want to have. YOU must always Count your Table Cell <td> count and ALWAYS match it, The following may be closer to what you want.

$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>';

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

    . '</tr>'
    . PHP_EOL
    ;
}
$out .= '</table>' . PHP_EOL;

Open in new window

Can you see where I added the <td> and </td> to get it>
0
 
LVL 33

Expert Comment

by:Slick812
ID: 40574289
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.
0
 

Author Closing Comment

by:DS928
ID: 40574322
It worked! Thank you.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now