0

This is driving me crazy.

I have three pages in this equation: nightmare.php, semi.php, and update.php.

Pieces of Code

nightmare.php

<a class="pull-right">
  <select class="navbar-inverse" onchange="showPage(this.value)">
  <option value="" disabled selected>Select Business Unit</option>
  <option value="/Nightmare/imes.php">IMES</option>
  <option value="/Nightmare/semi.php">SEMI</option>
</select></a>

<div id="txtHint"><b></b>

showPage() function

function showPage(str) {
  console.log(str);
  if (str !==".PM") {
    if (str=="") {
      document.getElementById("txtHint").innerHTML="";
      return;
    } 
  }
 if (str!=="/metrics.php") {

$("#txtHint").load(str, function () {

});
}}

The user begins by loading nightmare.php, which consists of a header bar with a dropdown (shown above). When they select SEMI, semi.php is called into the #txtHint div (also shown above)

semi.php

semi.php consists mostly of an HTML table populated with PHP and SQL. There are fields that the user can update. There is a submit button. When the user presses this submit button, those changes should be sent to the server and the user's view should be refreshed with the updated info.

The important piece is this line:

<form method="POST" action="update.php">

Problem

If load semi.php into the address bar, the table is displayed and I type in comments and hit the "update" button. Update.php launches and echos out the correct SQL code.

If I load nightmare.php instead, then select semi from the dropdown and populate semi.php into the DIV on nightmare.php, then click the update button, it loads update.php but update.php is blank and no code is executed to the server. I have looked through other projects I've written where I've done this same exact process and I can't see any discernible difference in the code that would allow me to understand why this doesn't work. I'm very confused!

Let me know if you need to see any other snippets of code to help me make sense of this.

Update 11/14/2014

Here is semi.php, with a few changes for brevity:

<?php session_start(); ?>
<!doctype html>
<html>     
  <head>        
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <link rel="stylesheet" href="/bootstrapstyle.css">    
    <link rel="stylesheet" href="/toastr.css">    
    <script type="text/javascript" src="/toastr.js"></script>             
    <script type="text/javascript" src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>         
    <script type="text/javascript" src="/tablesorter/jquery.tablesorter.js"></script>
    <style type="text/css">      body {         padding-top: 50px;         padding-bottom: 20px;       }     
    </style>  
    <style>
      .filter-table .quick { margin-left: 0.5em; font-size: 0.8em; text-decoration: none; }
      .fitler-table .quick:hover { text-decoration: underline; }
      td.alt { background-color: #ffc; background-color: rgba(255, 255, 0, 0.2); }
    </style>                                      
  </head>     
  <body>

<script>
$(document).ready(function() 
    { 
        $("#box-table-a")
        .tablesorter({textExtraction: 'complex'}); 
    } 
);  
</script>

<?php 
include('./nightmaredb.php');
$sqlQuery = "SELECT * FROM report";
$result     = mysqli_query($con, $sqlQuery);
?>          

<div class="jumbotron">
<div class="container">
  <h1 class="pull-left">Nightmare</h1>  
</div>

<div id="form-messages">           
<div class="container2">
<div class="row">
  <div class="col-xs-6 col-sm-4 col-lg-12">       
    <form id="updateNightmare" method="POST" action="update.php">
      <div class="container pull-left">
        <h2 class="pull-left">
          <input class="button" class="btn btn-default btn-lg" name="update"<?= $lineID ?>" type="submit" id="update" value="UPDATE">            
        </h2>        
      </div>
</div>
</div>
<div id="tableRefresh">
<table id="box-table-a" class="tablesorter">  
    <thead>
<th>SOLI</th>
<th>Branch</th>
<th>*... a few others...*</th>
</tr></thead>

<?php
while ($row = mysqli_fetch_array($result)) {

    $lineID             = $row['lineID'];   
    $soli               = $row['soli'];
    $branch             = $row['branch'];
    $warehouse          = $row['warehouse'];
    $acctNumber         = $row['acctNumber'];
    $customer           = $row['customer'];
    $resolutionComments = $row['resolutionComments'];

?>
<tr>
<td><?= $lineID ?><input name="lineID[]" value="<?= $lineID ?>"></td>
<td><?= $soli ?><input name="soli" value="<?= $soli ?>"></td>
<td><?= $branch ?><input name="branch" value="<?= $branch ?>"></td>
<td> *... a few others ...* </td>

<?php
}
?>
</table>
</form>
</div>
</div>
</div>
</div>
</div>

      <hr>
      <footer>
      </footer>
    <!-- /CONTAINER -->

  <script src="update.js"></script>  
  <script src="/filter/jquery.filtertable.min.js"></script>
  <script>
    $(document).ready(function() {
        $('table').filterTable();        
    });
  </script>

  </body>

</html>  
lordterrin
  • 165
  • 2
  • 2
  • 10
  • What do the error logs say? – Jay Blanchard Nov 13 '14 at 22:30
  • the developer console does not say anything - is there another place I can look to see errors? – lordterrin Nov 13 '14 at 22:34
  • server error logs or set [error_reporting](http://php.net/manual/en/function.error-reporting.php) – Derek Nov 13 '14 at 22:35
  • maybe also check for a whitespace somewhere around your php tags that doesn't belong - took me hours and hours to find one of those well hidden somewhere in a script. – Stefan Schuchlenz Nov 13 '14 at 22:36
  • this is awesome - I didn't know php kept logs. Let me run through this... `[13-Nov-2014 21:30:30 Europe/Berlin] PHP Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Nightmare\update.php on line 23` This specific line of code is `die('Could not update data: ' . mysqli_error($con));` – lordterrin Nov 13 '14 at 22:43
  • Ah - so your query isn't working! It is likely that you aren't setting the `$_POST` array variables that you need to successfully query the database. – Jay Blanchard Nov 13 '14 at 22:45
  • Actually - I think it's the line before it. The query isn't working because it can't open my file that contains the database info. I guess my syntax is wrong: `include(/Nightmare/db.php): failed to open stream: No such file or directory` The physical file is at `c:\xampp\htdocs\Nightmare\db.php` I've tried `include('/Nightmare/db.php');` and `include('db.php');` but I must still be doing it wrong.... – lordterrin Nov 13 '14 at 22:51
  • Okay - I fixed that - now I'm getting nothing in the PHP server logs, but the error still exists. It works FINE when I just load semi.php, but when I load semi.php inside the DIV on nightmare.php it doesn't work.... – lordterrin Nov 13 '14 at 22:56
  • If you're using jQuery, `$('txtHint').html('')` is a lot less messy than smashing around with `innerHTML` directly. The [`html()`](http://api.jquery.com/html/#html2) method accepts an argument to [re-write the HTML](http://stackoverflow.com/questions/1309452/how-to-replace-innerhtml-of-a-div-using-jquery). – tadman Nov 13 '14 at 23:13
  • I think semi.php would be very helpful to see. It is possible that the issue lies in having multiple forms on one page. Is the submit button inside of the
    tag you listed above? How are you submitting the form (Javascript validation?)? is there a form around the
    – Nate Nov 13 '14 at 23:44
  • I've updated my original question with semi.php - more than getting help making this work, I just want to understand what is causing this. From a technical perspective, it's really odd that it works FINE until I load it through the other page's DIV. – lordterrin Nov 14 '14 at 15:20

0 Answers0