Jump to content

Barand

Moderators
  • Content Count

    19,775
  • Joined

  • Last visited

  • Days Won

    411

Everything posted by Barand

  1. Around the turn of the century I had just discovered PHP and was currently using ASP with VB for intranet applications. One particular page enabled users to view log entries each day. This had worked fine for months when I received a complaint from one of the users that it was running very slowly. I tried it myself and, sure enough, it took about 15 seconds to display the data. Examining the entries in the SQL Server table for that day I noticed that there were some abnormally long text entries, way longer than usual. Curious about the time taken I decided to write the application in PHP (for the practice if nothing else) and see if that improved things. It did. For the same day, the screen displayed in 0.25 seconds. That was 70 times faster! Too good to be true, I thought. So I compared the two programs. The structure of the ASP program was loop get record concatenate output into a string endloop outout the string The PHP structure was loop get record output endloop The ASP structure was a better "separation of concerns" which is the method usually preached, but it did come at a cost as further experimentation was to prove. My next task was to rewrite the ASP using the PHP structure and vice versa so that I could get a much fairer comparison. As the chart below shows, concatenating does have an overhead (especially with long strings) and this is even more marked with VB which seemed extremely poor at handling the task.
  2. But as Mark Twain (?) commented "Canada's OK but not for the whole weekend"
  3. That's sabotaged my freebie hoilday to the States
  4. $50 per hour plus travel time and expenses
  5. The PHP code embedded inside html tags is just generating more html code dynamically (usually containing data extracted from a database) which becomes part of the overall html page. This then received by the browser (PHP's job is now done) on the client and rendered to display on the screen. EDIT: Your PHP code may look something like this <html> <body> <table border='1'> <tr> <th>IP ADDRESS</th> <th>PAGE VISITED</th> <th>PREVIOUS PAGE</th> <th>DATE</th> <th>TIME</th> </tr> <?php // printing table rows while($row = mysqli_fetch_row($sql)) { echo '<tr>'; foreach ($row as $col) { echo "<td>$col</td>"; } echo "</tr>\n"; } ?> </table> </body> </html> and what your browser then receives is something like this <html> <body> <table border="1"> <tr> <th>IP ADDRESS</th> <th>PAGE VISITED</th> <th>PREVIOUS PAGE</th> <th>DATE</th> <th>TIME</th> </tr> <tr><td>111.222.001.123</td><td>a.php</td><td>N/A</td><td>10/11/19</td><td>9:00am</td></tr> <tr><td>111.222.001.123</td><td>a.php</td><td>N/A</td><td>10/12/19</td><td>8:00am</td></tr> <tr><td>111.222.001.123</td><td>a.php</td><td>xyz</td><td>10/12/19</td><td>12:00pm</td></tr> <tr><td>111.222.001.123</td><td>a.php</td><td>N/A</td><td>10/12/19</td><td>1:00pm</td></tr> </table> </body> </html>
  6. You are creating variables that you never use ($column_count, $fields_num) Your HTML markup for the table is wrong You have two table opening tags. You should have a <tr> tag at start of every row, not just when $i==1. Use CSS styles instead of deprecated html attributes (eg width, align) You don't need the $conn->close(); - that happens anyway at the end of the script. Do not use "SELECT * ...". Specify the columns you want. (The table structure could be changed in future). I also told you earlier that dates should be stored as yyyy-mm-dd format. Same goes for times (hh:mm or hh:mm:ss). If you don't then you can't use them to order your data. mysql> SELECT time12 , time24 FROM tbtime ORDER BY time12; +--------+--------+ | time12 | time24 | +--------+--------+ | 2:00AM | 02:00 | | 2:00PM | 14:00 | | 4:00AM | 04:00 | | 4:00PM | 16:00 | | 6:00PM | 18:00 | | 8:00AM | 08:00 | | 8:00PM | 20:00 | +--------+--------+ You can reformat them for human benefit. <?php $dbHost = "localhost"; $dbName= "rptDatabase"; $dbUsername = "username"; $dbPassword = "password"; mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName); $sql = mysqli_query($conn, "SELECT ip , page , CASE WHEN referrer = '' THEN 'N/A' ELSE referrer END as referrer , DATE_FORMAT(date, '%m/%d/%y') as formatdate , TIME_FORMAT(time, '%l:%i%p') as formattime FROM tblTraffic ORDER BY ip, date, time"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> <style type="text/css"> table { font-family: verdana, sans-serif; font-size: 10pt; width: 100%; border-collapse: collapse; } th, td { width: 20%; text-align: center; padding: 8px; } th { background-color: #396; color: #FFF; } </style> </head> <body> <table border='1'> <tr> <th>IP ADDRESS</th> <th>PAGE VISITED</th> <th>PREVIOUS PAGE</th> <th>DATE</th> <th>TIME</th> </tr> <?php // printing table rows while($row = mysqli_fetch_row($sql)) { echo '<tr>'; foreach ($row as $col) { echo "<td>$col</td>"; } echo '</tr>'; } ?> </table> </body> </html>
  7. I have yet to meet the developer who's happy with GoDaddy. You are trying to connect to a MySQL database on GoDaddy's server, so the host is their server's server name or IP address. The username and password also need to be valid for access to that database on that server. Can you connect to the database using PhpMyAdmin? If so that's a good place to start with the right credentials.
  8. Be careful what privileges you give to an online connection. Just give the bare minimum required for the site to function.
  9. You've removed the ";" from the end of the statement
  10. https://www.php.net/manual/en/reserved.variables.server.php
  11. This should fly better <?php $dbHost = "ipaddress"; // USE $dbName= "rptDatabase"; // VALID $dbUsername = "username"; // CREDENTIALS $dbPassword = "password"; // HERE $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $page = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : ''; $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; // check they exist $date = date("Y-m-d"); $time = date("h:i:a"); mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); // tells mysqli to automatically report errors $conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);; $stmt = $conn->prepare("INSERT INTO tblTraffic (ip, page, referrer, date, time) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("sssss", $ip, $page, $referrer, $date, $time); $stmt->execute(); $stmt->close(); $db->close(); ?>
  12. Most of my last comments still apply. You haven't done much about those errors.
  13. It does if you have some of your own. There is no item in the $_SERVER array with the key "HTTP_REFERER" The username and password you are using to connect are invalid You are calling a mysql_ function and pasing it a mysqli object. (You cannot mix'n'match)
  14. Anything received from an external source can be "fiddled with".
  15. You would only be sending a product id number, not your bank details.
  16. Check the "Core" section in the output from phpinfo(). That will tell you what's happening regarding error reporting settings. You may not have to do anything other than find your php_error.log
  17. You'd have to try some likely ones and see. One possibility is that errors are reported and logged instead of being displayed. Check for a php error log.
  18. It will be on the php host server. Maybe there is a cPanel to access it or something similar
  19. Run this script <?php phpinfo(); ?> The first few lines of the output should contain a line like this
  20. Start by turning on the error reporting function of PHP. There are at least 3 that I've spotted.
  21. Barand

    census bureau

    I'm surprised you don't appear store the data anywhere, except maybe in SESSION, so you have to reenter all the data each time you want to view the analyses. And why 4 pages and not just
  22. All function beginning with mysql_ are obsolete, replaced several years ago by either mysqli_ (improved) or PDO and removed completely from PHP 7.0 onwards.. The consensus is that PDO is better than mysqli. I assumed it's turned off as you aren't apparently getting warning messages about the use of mysql_* functions. The settings are in your php.ini file. It could be the version of PHP is obsolete.
  23. The list of what you are doing right might be shorter, however... You are using obsolete MySQL_ functions. Use PDO instead. string values in a query need to be inside quotes eg VALUES ('$ip', '$page', ...etc) You should be using prepared queries so input values are not inserted directly into the query statement You should always store dates in a database in yyyy-mm-dd format Instead of calculating current time and date in PHP then putting them in the query, just use a TIMESTAMP column which will update automatically You probably haven't got error reporting turned on
  24. I see you can't take hint. Don't repost the same topic.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.