where to look

Discussion in 'General Software' started by 1Tsme1941, Feb 16, 2020.

  1. 1Tsme1941

    1Tsme1941 Member

    Messages:
    49
    The code below only produces: see screenshot: doesn't list records. what am I doing wrong?


    <html><head>
    <style>
    @page { size 8.5in 11in; margin: 2cm }
    div.page { page-break-after: always }
    </style>
    </head><body><center>
    <div class="page">
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    // error_reporting(0);
    mysql_connect('localhost','root','');
    mysql_select_db('lookupdb') or die("Unable to select database");
    $query=" SELECT target, purpose, username, password, email, sec?, secAns, visits, lastdate,
    lasttime, saved FROM `lookuptbl`;
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    echo date('m/d/y');
    ?>
    <font size=+1><b><center> lookup database list</font></center></b></b><br />
    <table cellspacing=0 cellpadding=0 border=1>
    <thead>
    <tr bgcolor="#ccffff">
    <th>target</th>
    <th>purpose</th>
    <th>username</th>
    <th>password</th>
    <th>email</th>
    <th>sec?</th>
    <th>secAns</th>
    <th>visits</th>
    <th>lastdate</th>
    <th>lasttime</th>
    <th>saved</th>

    </tr>
    <?php
    while($row = mysql_fetch_array($result))
    {
    echo '
    <tr>
    <td>', $row['target'], '</td>
    <td>', $row['purpose'], '</td>
    <td>', $row['username'], '</td>
    <td>', $row['password'], '</td>
    <td>', $row['email'], '</td>
    <td>', $row['sec?'], '</td>
    <td>', $row['secAns'], '</td>
    <td>', $row['visits'], '</td>
    <td>', $row['lastdate'], '</td>
    <td>', $row['lasttime'], '</td>
    <td>', $row['saved'], '</td>
    </tr>';
    }
    </table>';

    echo "Page 1";
    ?>
    </div>
    <div class="page">
    <?phphttp
    echo "Page 2";

    mysql_close();
    ?>
    </body></html> datalist.png
     
  2. revolution221

    revolution221 Member

    Messages:
    55
    Is your query string supposed to have a beginning quote with no closing quote?

    you have

    Code:
    $query=" SELECT target, purpose, username, password, email, sec?, secAns, visits, lastdate,
    lasttime, saved FROM `lookuptbl`;
    but shouldn't it be

    Code:
    $query="SELECT target, purpose, username, password, email, sec?, secAns, visits, lastdate,
    lasttime, saved FROM `lookuptbl`";
     
  3. 1Tsme1941

    1Tsme1941 Member

    Messages:
    49
    I made the change with same result
     
  4. 1Tsme1941

    1Tsme1941 Member

    Messages:
    49
    OK, I'm lost. Is my php not working, mysgl not working, my server not working, none, all?
    ==========================================================
    my include statement( include('homedb-connect.php'); :
    -----------------------------------------------------------
    <?php
    $con=mysqli_connect("localhost","root","","homedb");
    // ============== check connection
    if(mysqli_errno($con))
    {echo "Can't Connect to mySQL:".mysqli_connect_error();}
    else
    {echo "</br>";}
    ?>
    --------------------------------------------
    should produce error message if no connect?
    ===============================================
    this code:
    -------------------------
    <!DOCTYPE html><html>
    <head></HEAD>
    <body><center><b>

    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    // error_reporting(0);
    include('homedb-connect.php');
    $query = "SELECT * FROM `lookuptbl` WHERE `target` = `$target` ORDER by target Asc";
    $result = $mysqli->query($query) or die($mysqli->error.__LINE__);
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
    {

    // Open the table
    echo "<table>";
    echo "<tr bgcolor="#ccffff">";
    echo "<td>$target</td>";
    echo "<td>$purpose</td>";
    echo "<td>$username</td>";
    echo "<td>$password</td>";
    echo "<td>$emailused</td>";
    echo "<td>$visits</td>";
    echo "<td>$lastdate</td>";
    echo "<td>$lasttime</td>";
    echo "<td>$saved</td>";
    echo "</tr>";
    echo "</table>";
    ?>
    </b></center></body></html>
    ---------------------------------------
    should display the table?
    =======================================

    this is produced:
    ----------------------
     

    Attached Files:

    • ugh.png
      ugh.png
      File size:
      146.6 KB
      Views:
      2
  5. Cromewell

    Cromewell Administrator Staff Member

    Messages:
    15,448
    You need a webserver running php for this to work. You can't just open the file in a browser. The browser only understands html, javascript and css.

    Chances are you need to name the file php to get the interpreter to run as well. (ie. http://localhost/read-junk.php). C:\Users\charlie\Documents\read-junk.html will always produce literal output.


    With the caveat that I have not written php in a good while, the pattern used to be:
    Code:
    $con=mysqli_connect("localhost","root","","homedb");
    if (! $con) {
      echo "Uhoh!";
    }
    
    That being said, the php manual does have both ways used.

    For actual code issues:
    Those look like backticks instead of single quotes to me ( ` vs ' ), one is by escape and what you don't want and the other is by the enter key.

    I don't know where $target is coming from, it just starts showing up in your code.

    You'll also want to escape the variables you are subbing into your query string, otherwise you open your stuff up to injection.
     
  6. 1Tsme1941

    1Tsme1941 Member

    Messages:
    49
    Keep getting advice from forums and w/thanks. I keep trying code that has worked before. I use xampp, even new versions. I suspect that Windows stopped support for win7 my PHP is corrupted and not functioning. I clicked on error logs and on PHP got "cannot find path". thoughts?
     
  7. Cromewell

    Cromewell Administrator Staff Member

    Messages:
    15,448
    When using xampp, you need to make sure you are accessing the served version, not the direct from disk version. In your screenshots it looks like you are always opening the file directly in the browser.
    Without the full line I don't know.
     
  8. 1Tsme1941

    1Tsme1941 Member

    Messages:
    49
    Cromewell, I truly thank for taking time to help, please do. If I possessed your knowledge, I'd say "well alrighty then, that explains everything".
    I have confirmed the presence of Homedb and lookuptbl and content
    ----------------------------------------------------------

    I have confirmed the presence of Homedb and lookuptbl and content
    ----------------------------------------------------------
    this confirms the prescence of the linking and linked files:

    #1 = shot of "home" files
    #2 = shot of link(html) (read-junk.html)
    #3 = shot of php result(object not found)
    #4 = shot of html result(read-junkHnP)
    ==============================================================
    HTML code:

    <html><body>

    <!-- read-junk.html -->

    <center>
    <a href="http://localhost/home/read-junk.php">load junk.php</a>
    </center></body></html>
    ---------------------------------------
    produces #2

    =====================================================
    PHP code:

    <html><head>
    <style>
    @page { size 8.5in 11in; margin: 2cm }
    div.page { page-break-after: always }
    </style>
    </head><body>

    <!--read-junk.php -->
    <center>
    <div class="page">
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    // error_reporting(0);
    mysql_connect('localhost','root','');
    mysql_select_db('lookupdb') or die("Unable to select database");
    $query=" SELECT target, purpose, username, password, email, visits, lastdate,
    lasttime, saved FROM `lookuptbl`;
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    echo date('m/d/y');
    ?>
    <font size=+1><b><center> lookup database list</font></center></b></b><br />
    <table cellspacing=0 cellpadding=0 border=1>
    <thead>
    <tr bgcolor="#ccffff">
    <th>target</th>
    <th>purpose</th>
    <th>username</th>
    <th>password</th>
    <th>email</th>
    <th>visits</th>
    <th>lastdate</th>
    <th>lasttime</th>
    <th>saved</th>

    </tr>
    <?php
    while($row = mysql_fetch_array($result))
    {
    echo '
    <tr>
    <td>', $row['target'], '</td>
    <td>', $row['purpose'], '</td>
    <td>', $row['username'], '</td>
    <td>', $row['password'], '</td>
    <td>', $row['email'], '</td>
    <td>', $row['visits'], '</td>
    <td>', $row['lastdate'], '</td>
    <td>', $row['lasttime'], '</td>
    <td>', $row['saved'], '</td>
    </tr>';
    }
    </table>';

    echo "Page 1";
    ?>
    </div>
    <div class="page">
    <?phphttp
    echo "Page 2";

    mysql_close();
    ?>
    </body></html>
    ----------------------------------------------------
    clicking on link produces #3
    ==================================================
    this HTML code:

    <html><head>
    <style>
    @page { size 8.5in 11in; margin: 2cm }
    div.page { page-break-after: always }
    </style>
    </head><body>

    <!--read-junkHnP -->

    <center>
    <div class="page">
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    // error_reporting(0);
    mysql_connect('localhost','root','');
    mysql_select_db('lookupdb') or die("Unable to select database");
    $query=" SELECT target, purpose, username, password, email, visits, lastdate,
    lasttime, saved FROM `lookuptbl`;
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    echo date('m/d/y');
    ?>
    <font size=+1><b><center> lookup database list</font></center></b></b><br />
    <table cellspacing=0 cellpadding=0 border=1>
    <thead>
    <tr bgcolor="#ccffff">
    <th>target</th>
    <th>purpose</th>
    <th>username</th>
    <th>password</th>
    <th>email</th>
    <th>visits</th>
    <th>lastdate</th>
    <th>lasttime</th>
    <th>saved</th>

    </tr>
    <?php
    while($row = mysql_fetch_array($result))
    {
    echo '
    <tr>
    <td>', $row['target'], '</td>
    <td>', $row['purpose'], '</td>
    <td>', $row['username'], '</td>
    <td>', $row['password'], '</td>
    <td>', $row['email'], '</td>
    <td>', $row['visits'], '</td>
    <td>', $row['lastdate'], '</td>
    <td>', $row['lasttime'], '</td>
    <td>', $row['saved'], '</td>
    </tr>';
    }
    </table>';

    echo "Page 1";
    ?>
    </div>
    <div class="page">
    <?phphttp
    echo "Page 2";

    mysql_close();
    ?>
    </body></html>
    --------------------------------
    produces #4
    ==============================================
    can you or someone, given this info, tell me why I can't read data from my database?


    homedb.png Untitledread-junk html.png homedb.png Untitledread-junk html.png not found.png read-junkHnP.png
     
  9. Cromewell

    Cromewell Administrator Staff Member

    Messages:
    15,448
    Screenshot #3 looks closest to how you want to access the page.

    I'm going to assume you have not changed any of the xampp configuration, so what you need to do is put your php into your hosted directory. This will usually be C:\xampp\htdocs. Entering http://localhost can only access files that your server is hosting and it is jailed so that all your stuff isn't posted for the world to see. If you can find your apache http.conf you can find the DocumentRoot config item to see where this folder is.

    An easy way to cheat is to find where the phpmyadmin directory is and make a directory in the same folder as it and put your code there. Then you would run the code by entering http://localhost/thefolderyoumade/read-junk.php. i.e C:\xampp\htdocs\phpmyadmin and C:\xampp\htdocs\home and then put your code in the home directory.
     
  10. 1Tsme1941

    1Tsme1941 Member

    Messages:
    49
    I'm working in "home" folder which is in "htdocs" folder.
     
  11. Cromewell

    Cromewell Administrator Staff Member

    Messages:
    15,448
    Double check the permissions of the file and what user apache is running as, you may need to grant additional permissions. The 404 error says that the server cannot find home/read-junk.php under htdocs.
     
  12. 1Tsme1941

    1Tsme1941 Member

    Messages:
    49
    guys I appreciate all your input. one down probably more to come. again thanks
     

Share This Page