Jump to content

Search the Community

Showing results for tags 'php'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 937 results

  1. iwato

    Matomo - PHP Direct (for Dummies)

    NATURE: This is part of a steadfast effort to hack through the thicket of PHP classes and namespaces of which the Matomo application consists. It is not an endeavor for the weak or timid, as the thicket is formidable and the documentation obscure. BACKGROUND: In order to submit a proper report request to the Matomo application the values of certain variables must be known. Although there are generators within the application that have been created to achieve this task, they are not easily accessible, as the thicket is, well, thick. Please find below both the file and code that produces the error message provided. The FILE: <?php /** * Piwik - free/libre analytics platform * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * * @package Piwik */ use Piwik\ErrorHandler; use Piwik\ExceptionHandler; use Piwik\FrontController; if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) { ErrorHandler::registerErrorHandler(); ExceptionHandler::setUp(); } FrontController::setUpSafeMode(); if (!defined('PIWIK_ENABLE_DISPATCH')) { define('PIWIK_ENABLE_DISPATCH', true); } if (PIWIK_ENABLE_DISPATCH) { $environment = new \Piwik\Application\Environment(null); $environment->init(); $controller = FrontController::getInstance(); try { $controller->init(); $response = $controller->dispatch(); if (!is_null($response)) { echo $response; } } catch (Exception $ex) { ExceptionHandler::dieWithHtmlErrorPage($ex); } } The CODE: require_once ('../../../../nudge.online/_utilities/php/matomo/core/dispatch.php'); The ERROR MESSAGE: LINE 16 ErrorHandler::registerErrorHandler(); Now, including the file ErrorHandler.php does not help. Neither does a call to the static function registerErrorHandler() appear to make a difference. Piwik\ErrorHandler::registerErrorHandler(); For the response is always the same Any ideas? Roddy
  2. BACKGROUND: I would like to embed a Matomo widget into a page, but I dare not embed it directly. For, to do so would require that I expose the authorization token that enables knowledgeable visitors of Matomo -- and coding in general -- the ability to view everything about my website that I am able to view. As I, myself, do not yet know what to do with everything that Matomo makes available (it appears endless), I certainly do not want to put it all into the hands of others willy-nilly. It is simply bad business. OBJECTIVE: Read the data into a PHP file, and load the result into the src attribute of an iframe. Below is sample code taken directly from the Matomo website. (The absence of the authorization token assumes that the superuser has given access to all users the right to view whatever they like. I do not wish to grant this privilege). SIMPLE URL https://www.nudge.online/_utilities/php/matomo/index.php?module=Widgetize&action=iframe&widget=1&moduleToWidgetize=Live&actionToWidgetize=getSimpleLastVisitCount&idSite=1&period=day&date=yesterday&disableLink=1&widget=1 EMBEDDING CODE <div id="widgetIframe"><iframe width="100%" height="350" src="https://www.nudge.online/_utilities/php/matomo/index.php?module=Widgetize&action=iframe&widget=1&moduleToWidgetize=Live&actionToWidgetize=getSimpleLastVisitCount&idSite=1&period=day&date=yesterday&disableLink=1&widget=1" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe></div> Obviously, there is no difference in the URLs. QUESTION: If an image can be created by a PHP file and then read into the src attribute of an image tag, surely it must then also be possible to read the HTML content of a PHP file into the src attribute of an iFrame. What is the necessary header argument required? I have tried both " header('Content-Type: text/html'); and header('Content-Type: text/plain'); Neither works! Or, am I just guessing. And, what I am trying to do simply does not work. Roddy
  3. I would like to share with you a message that I posted on the Matomo forum for which I am not expecting a satisfactory reply. I suspect that Matomo will be unwilling to entertain the idea for fear of opening a Pandora's box of insecurity for casual users and thereby endangering its reputation as a secure web utility. Matomo's fear need not be my own, however, with the proper guidance. BACKGROUND: After several weeks of enormous frustration I was finally able to access the Matomo web application directly with PHP. I was able to achieve this somewhat (for me) monumental task by renaming the .htaccess file (see below) in the /matomo/config folder and thus canceling its prohibitive effect. Obviously, this file was placed in the /matomo/config folder as a matter of security -- security, mind you, that I do not wish to compromise. This said, an unending series of HTTP requests uses up an enormous number of resources, and I wish to share the data that I collect about my users with my users via my own custom-built PHP files for which I require direct communication with the Matomo application. (I have no desire to play the governmental game of protect-and-deceive -- read GDPR or NSA). So, I explored the internet and found alternative contents <https://www.slicewise.net/php/piwik-absichern/> to the current .htaccess file in use by Matomo as of 3.5.1. REQUEST: Would anyone like to comment on the merging of these two files (see below) into a workable arrangement that would give me the superuser direct access to the Matomo web-application via PHP, but deny access to everyone else except through those channels already set in place by Matomo for anonymous users and opt-in/out visitors. PROPOSED FILE <Files "*"> AuthUserFile /path/to/piwik.htpasswd AuthName Piwik-Password AuthType Basic <RequireAny> Require valid-user Require ip 127.0.0.1 <your-server-ip> #needed for some scripts </RequireAny> </Files> <Files ~ "^piwik\.(js|php)|robots\.txt|idxsec\.php|favicon\.ico$"> Require all granted </Files> CURRENT FILE <Files "*"> <IfModule mod_version.c> <IfVersion < 2.4> Order Deny,Allow Deny from All </IfVersion> <IfVersion >= 2.4> Require all denied </IfVersion> </IfModule> <IfModule !mod_version.c> <IfModule !mod_authz_core.c> Order Deny,Allow Deny from All </IfModule> <IfModule mod_authz_core.c> Require all denied </IfModule> </IfModule> </Files> My goal is to give my visitors an important glimpse into the reality of data collection and analysis. I now know that I am able to do this my eliminating the .htaccess file. Elimination of the file is, however, not my goal. Roddy
  4. BACKGROUND: I have now tried a number of ways to make two cURL calls within the same Javascript (jQuery) routine. For each new way, I have discovered what I believe to be a reasonable explanation for my failure. For my most recent attempt, however, a good explanation is not forthcoming. To be sure, single AJAX calls with a single cURL call for each yield the desired results. Simply I cannot seem to combine these results simultaneously on the same page. The scenario given below, for example, returns the desired outcome for the second cURL call, but not the first. JAVASCRIPT: $.ajax({ url: '.../VisitsSummary.php', method: 'GET', data: {methodName : '_get', methodName : '_getSumVisitsLengthPretty'}, dataType: 'JSON', statusCode: { 404: function() { alert( "Page not found" ); }}, success: function(visitsSummary_data) { console.log(visitsSummary_data); var tv = visitsSummary_data.nb_visits; var uv = visitsSummary_data.nb_uniq_visitors; var visits_per_unique_visitor = Math.round(tv/uv * 10)/10; $('#so_total_visits').html(visitsSummary_data.nb_visits); $('#so_unique_visitors').html(visitsSummary_data.nb_uniq_visitors); $('#visits_per_visitor').html(visits_per_unique_visitor); $('#so_average_time_spent').html(visitsSummary_data.avg_time_on_site); } }); PHP: if (isset($_GET['methodName'])) { $method_name = $_GET['methodName']; if ($_GET['methodName'] == '_get') { $url = 'https://.../index.php?module=API&action=index&method=VisitsSummary.get&idSite=1&period=year&date=today&format=json&token_auth=&token_auth=...'; $curl_request = curl_init(); curl_setopt($curl_request, CURLOPT_URL, $url); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, false); curl_exec($curl_request); if(curl_errno($curl_request)) { echo 'Curl error: ' . curl_error($curl_request); } curl_close($curl_request); } if ($_GET['methodName'] == '_getSumVisitsLengthPretty') { $url = 'https://.../index.php?module=API&action=index&method=VisitsSummary.getSumVisitsLengthPretty&idSite=1&period=year&date=today&format=json&token_auth=&token_auth=...'; $curl_request = curl_init(); curl_setopt($curl_request, CURLOPT_URL, $url); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, false); curl_exec($curl_request); if(curl_errno($curl_request)) { echo 'Curl error: ' . curl_error($curl_request); } curl_close($curl_request); } } QUESTION: Can you find anything wrong with the above strategy? If so, what would you recommend to replace it? Roddy
  5. I watch more student ask for the PHP code of OTP verification through Email. I think it is very good quary from student. Please help me to make this code as project. and i request W3SCHOOL to post this code in the website. !!!!!! THANK YOU !!!!!
  6. BACKGROUND: I have a plain text file with an .html extension. In the file is a <p> element into which I would like to enter the current date. The file is called from its hostpage via a jQuery $.get() statement that is followed with an AJAX call to a PHP processing file that returns JSON that can be processed in the AJAX success function as an object. QUESTION: If I place the PHP necessary to create the date in the text file with the .html extension, will it appear in the hostpage when called by the $.get() method? NOTE: My server is programmed to accept PHP in files with a .html extension. Mind you, the text file has neither <head>, nor <body> element, let alone a <DOC> header. Roddy If I enter the data with PHP before the AJAX
  7. BACKGROUND: Recently I learned how to embed directly a Matomo widget into my website. Although there are several ways to make this happen, I am only able to achieve two of them at this time: one, gives all autonomous users access to all Matomo's reporting widgets and a large number of reporting methods; the other, exposes the superuser's authorization token that would leave a disastrous breach in database security. DILEMMA: Although I am able to retrieve the widget via CURL in an invisible PHP file, and consequently embed the widget's contents via the src attribute of an iframe, I am not able to do so with the same rich formatting that can be achieved when the same HTTP request is placed directly into the src attribute of the iframe. Either cURL is stripping away valuable information or the Browser is unable to process the information provided in the format provided. QUESTION: What must I do in order to get cURL to behave in a manner that produces information compatible with an ordinary web-browser? Roddy
  8. Sigmahokies

    Insert into in PHP

    Hi everyone, I am trying to get all data from input in HTML, then post in php to insert into the database (phpmyadmin), seem it doesn't work. I checked for misspelling, and checked followed very correct, but it won't work, even it did not show what is error. "require.php" file is a connect to database. Can you help? Thanks, Gary <?php require("require.php"); $first = $_POST['first']; $last = $_POST['last']; $address = $_POST['address']; $address2 = $_POST['address2']; $city = $_POST['city']; $state = $_POST['state']; $birth = $_POST['birth']; $zip = $_POST['zip']; $home = $_POST['home']; $mobile = $_POST['mobile']; $gender = $_POST['gender']; $insert = "INSERT INTO register ( ASL-PT_ID, FirstName, LastName, Address 1, Address 2, City, State, Zip, BirthDate, Home, Mobile, Gender) VALUES ('$first', '$last', '$address', '$address2', '$city', '$state', '$zip', '$birth', '$home', '$mobile', '$gender')"; if ($first && $last && $address && $address2 && $city && $state && $zip && $birth && $home && $mobile && $gender) { mysqli_query($GaryDB, $insert) or die("Could not add in the Database"); } ?>
  9. How i make a Real time comment-replay script system in a website ?
  10. westman

    cookie coding

    Hi all, I am coding cookies for the first time and here is what I have. setcookie("username", $old_cookie, "1", "/", "", "", TRUE); setcookie("username", $new_cookie, strtotime( '+30 days' ), "/", "", "", TRUE); Is this the right way of resetting the value of one cookie? ps. I did read a lot on http://php.net/manual/en/function.setcookie.php but it is not clear.
  11. Sigmahokies

    Validation form

    Hi everyone, I am trying to have validation form, seem it doesn't work. what did I do wrong? If anyone can help, Thank you so much... Gary Taylor <?php $buzz = $buzz2 = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { if (empty($_POST['select'])) { $buzz = "<h2><color ='red'> >- </color></h2>"; $buzz2 = "<h2><color ='red'> -< </color></h2>"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Welcome to ASL-PT Scoring</title> <link href="default.css" rel="stylesheet" type="text/css"> </head> <body> <fieldset> <h1>Welcome to ASL-PT Scoring website</h1> <table> <form action="login.php" method="post"> <select name="select"> <?php echo $buzz ?><option value="" >Please select the level</option><?php echo $buzz2 ?> <option value="Administrator">Administrator</option> <option value="License">License</option> <option value="Scorer">Scorer</option> </select> <caption>Please login to enter the site below:</caption> <tr><td>Username:</td><td class="td"><input type="text" name="user"></td></tr> <tr><td>Password:</td><td class="td"><input type="password" name="password"></td></tr> <tr><td colspan="2"><input type="submit" name="submitted" value="Login"></td></tr> </form> </table> </fieldset> </body> </html>
  12. BACKGROUND: My jubilation was short-lived. For the internal server error that was plaguing my site in general is now plaguing a crucial file in particular. Please find below a file that works perfectly well on my local test server, but fails with an internal server error on my host server. Please also note that the file matomo/index.php is located on the same server as that from which the cURL call is made, but under a different domain name. ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log'); ini_set('html_errors', 0); ini_set('display_errors', 0); error_reporting(E_ALL); $url = 'https://.../matomo/index.php?module=API&method=API.getIpFromHeader&format=JSON&token_auth=...'; $curl_request = curl_init(); curl_setopt($curl_request, CURLOPT_URL, $url); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, false); curl_exec($curl_request); curl_close($curl_request); QUESTION: Does cURL not work in such an environment? If it does, then what must I do to make it work? The error.log file contains nothing and the AJAX that made the call does not complain of not being able to access the file. Roddy
  13. BACKGROUND: A visitor arrives on a website. While still on the site he triggers an AJAX call that fills a <div> element with new HTML. Once the page is filled another AJAX call is made that seeks to read the following value as encoded JSON: $_SERVER['REMOTE_REFERER']. Instead I receive a 500 internal server error. The AJAX (function() { $("#main").html(''); $("<link/>", { rel: "stylesheet", type: "text/css", href: "./_utilities/css/yourprofile_filler.css" }).appendTo("head"); $.get('./yourprofile_filler.html', function(data) { $('#main').html(data); }).done(function(){ $.ajax({ url: './_utilities/php/visitor_ip.php', dataType: 'JSON', statusCode: { 404: function() { alert( "Page not found" ); }}, success: function(visitor_ip) { console.log(visitor_ip); } }); }); })(); The PHP <?php $referral_addr = $_SERVER['REMOTE_REFERER']; echo json_encode($referral_addr); ?> ERROR MESSAGE jquery.min.js:5 GET https://www.grammarcaptive.com/_utilities/php/visitor_ip.php 500 (Internal Server Error)send Is the $_SERVER variable not available in the moment of the AJAX? How do I otherwise make it available? Roddy
  14. BACKGROUND: I am querying a MySQL database with a Matomo GUI. The API is called imageGraph. The call to the API works, as I have produced the desired image by assigning the URL as the value of an href attribute of an HTML <a> element. When using this link to display the image the image appears on a new page with its own header. This is not the effect that I desire. My goal is to display the image within a <div> tag on a webpage. The code that is suppose to achieve this latter effect is provided below. The URL that fetches the data from the API is identical for both the link and the PHP processing page for the AJAX call provided below. The PHP (./practice.php) $url ='https://.../matomo/index.php ?module=API &method=ImageGraph.get &idSite=1 &apiModule=Referrers &apiAction=getReferrerType &token_auth= ... &period=day &date=2018-04-10,2018-05-09'; $curl_request = curl_init(); curl_setopt($curl_request, CURLOPT_URL, $url); curl_exec($curl_request); curl_close($curl_request); The HTML <div id='referral_types'> <img src='' alt='Line Chart of Referral Types' /> </div> The Javascript $(document).ready(function() { $.ajax({ method: 'GET', url: "./practice.php", cache: false, contentType: 'image/png', success: function(response) { console.log(response); var graphic_src = response; $('#referral_types').find('img').attr('src', graphic_src); } }); }); EXPERIMENTATION: The console indicates that practice.php has been read, as it is filled with the kind of character nonsense typical of an image file. As the API permits an optional &format parameter I experimented with several including the following: AJAX PHP dataType JSON, &format=json dataType XML &format=xml (omit) &format=original The result was invariably the same. The ALT message with no image. Please advise. Roddy
  15. sgt_spike

    Content not showing

    I have a table pulling data from a database. Everything works getting the data to show in the table, however the content under the table isn't showing up. I'm using bootstrap 4.0 for layout, so I have rows and cols with the table being the third row and two other rows, not showing, under the 3rd row. I've moved one row about the table row and it show up, but put it back under the table and it disappears. I've ensured I have the right amount of div tags for each of the rows and cols. I'm at a loss
  16. Hi all, I have a php file to check a users input and it seems pretty straight-forward as far as logic goes, but the variable seems to be concatenating the "badEntry" onto its return value. I've been over it and over it and can't seem to see what's wrong. I originally had $userInput as the only return variable, but when I started having trouble I added the $toReturn variable to hopefully make it clear what I was doing wrong. Didn't help. I enter 'sakde12345' and I get that back with 'BadEntry' concatenated to it - looks like this - sakde12345BadEntry. My callback function is supposed to see if the return value is equal to 'BadEntry' and of course it isn't because it somehow includes the original input in front of it. It's returning this for either 'good' or 'bad' input. Can anyone figure out how I've miscoded or what? I also had a question about the debugger in chrome when I was running the js that called this php in the xmlhttprequest. The debugger traced thru everthing OK, but when it came to the 'onreadystatechange', it went to the 'xhr.open' line, jumped back to the onreadystatechange ( which became 1) but then it jumped to the requestheader line, then the .send line, then it jumped back to the js function that called the xhr request, then it jumped all the way back to the button in html that submitted the input. That kind of surprised me to see that - is the program just gathering information to proceed or something like that? I know it's kind of a weird question, but I'd like to understand what is going on. Thanx for any help, and I appreciate your patience!!! <?php $toReturn = ""; $userInput = ""; $chars = []; $i = 0; if ($_SERVER["REQUEST_METHOD"] == "POST"){ $userInput = $_POST["userID"]; // Get variable passed to xmlhttp call $userInput = test_input($userInput); // Run it thru easy data cleaner $userInput = strtolower($userInput); // change all to lower case $toReturn = $userInput; $chars = str_split($userInput); // split input into single characters if (strlen($userInput) != 10) { // is the input exactly 10 chars long $toReturn = "BadEntry"; } else { if (substr($userInput,0,3) != "sak") { // are the 1st 3 letters 'sak' $toReturn = "BadEntry"; } else { if (is_not_Char($chars[3]) || is_not_Char($chars[4])) { // are the 4th & 5th chars letters - name initials $toReturn = "BadEntry"; } else { for ($i = 5; $i < 10; $i++){ if (is_not_Numb($chars[$i])) { // are the last 5 chars Numbers $toReturn = "BadEntry"; } } } } } } echo $toReturn; function is_not_Char($examp){ $charBool = false; if ($examp < chr(97) || $examp > chr(122)) { // is it a lowercase letter - ascii 97 - 122 $charBool = true; } echo $charBool; } function is_not_Numb($examp){ $charBool = false; if ($examp < chr(48) || $examp > chr(57)) { // is it a number - ascii 48 - 57 ( 0 - 9 ) $charBool = true; } echo $charBool; } function test_input($data) { // standard data cleansing tools $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); echo $data; } ?>
  17. BACKGROUND: Working with Matomo has compelled me to dig deeper into the way that information gets passed over the internet. Up until now I have assumed that I can pass just about anything in a query string. In fact, this is exactly what I have been doing. What I am beginning to realize is that the PHP $_POST and $_GET variables have been doing work of which I was not aware. I have come to this conclusion with my new encounter of the encodeURI(), encodeURIComponent(), decodeURI(), and decodeURIComponent() functions. Indeed, I have read that no information can be passed in an HTTPRequest that is not in ASCII format. Is this true? QUESTION: Is it true that when working with PHP the values of PHP HTTPRequests are automatically URL encoded and URL decoded, and that when working with Javascript the same values must be manually encoded and decoded? Roddy
  18. Hi all, I have a couple of questions that popped up while studying php; really not questions, but I want to get some confirmation that my deductions are correct from what I've figured out. I was getting very confused over the differences in the object-oriented mysqli and the procedural mysqli and translating from one to the other. I think I like using OOps better The reference list on w3 only shows the procedural syntax so I wanted to make sure I was coming up with the correct OOps. Things like 'mysqli_query($conn,$sql)' becomes '$conn->query($sql)'. I could see that quite clearly in the tutorial, but some others get a little hazy like 'mysqli_free_result($result)' becomes '$result->free_result'. Do I have this correct? and is there a rule about changing from one to the other - like whatever the object of the function is goes first in the OOps syntax, or something. Now I noticed that when you check for a connection error the OOps syntax says '$conn->connect_err' while the procedural syntax is 'mysqli_connect_error()' with nothing in the parenthesies. Is that because the connection object hasn't actually been established yet? or some other mysterious reason. I also had a quick question about .php files in general. The w3 said that a file with php in it should end with .php, but when I do that the server won't execute it - so I change it to html and its OK. Now if I have a file with exclusively php code and I don't 'echo' any output, but only 'return' a value, do I still need to write the <!DOCTYPE> and other tags like <head>, etc. Or can I start the file with <?php and end it with ?>. Like I said , I think I have these things correctly in my mind, but if I'm not right I want to nip it in the bud and make sure I'm off on a good foundation. I've experimented with different ideas, but if it doesn't work, sometimes you can't figure out what you did wrong. Thank you so much for your input and answers!!
  19. Hello I'm facing a problem I cant really solve. I want to place a backlink in the shape of either a textlink or an img banner outside my own server. (for instance inside an iframe) I want to be able to track download impressions and referrer clicks. Can this be done with php or not? It seems technically not possible to place php on someone else's server. What would you recommend?
  20. Hallo, Can anybody help for this question. I have changed my computer. And now my browser (google chrome) can not read php-files from my computer. I have installed PHP from XAMPP. What may be the reason for this?
  21. honkmaster

    CURDATE() not working for next month

    Hi I have a query that returns the count of entries based on CURDATE(), it works for any dat in this month (April) but does not work for next month (May). I think it is something to do with CURDATE()+3 returns 2018-04-31 which should be 2018-05-01 This Works as Date is in April SELECT COUNT(Machine) FROM production WHERE Status = 'Confirmed' AND DATE(FROM_UNIXTIME(production.Required)) = CURDATE() This does not work as in May SELECT COUNT(Machine) FROM production WHERE Status = 'Confirmed' AND DATE(FROM_UNIXTIME(production.Required)) = CURDATE()+3
  22. i want to build a bar chart with chartJS and database mysql with two different query, but bar chart not showing. can anyone help me to correct the code? this my query and javascript: <?php $a = mysqli_query("select count(a) as total1 from tbl"); $b = mysqli_query("select count(b) as total2 from tbl"); ?> <body> <div> <canvas id="chart"></canvas> </div> <script> var ctx = document.getElementById("chart"); var chartdata = { labels: 'CHART', datasets: [{ label: "A", data: [<?php while ($data1 = mysqli_fetch_array($a)) {echo '"''.$data1['total1'].'",';}?>], backgroundColor: "#000000" },{ data: [<?php while ($data2 = mysqli_fetch_array($b)) {echo '"''.$data2['total2'].'",';}?>], backgroundColor: "#ffffff" }] }; var chart = new Chart(ctx, { type: 'bar', data: chartdata }); </script> </body>
  23. Sigmahokies

    Flexible in array for table in the Database

    Hi everyone, I am trying to set up the flexible with array, like set up the array by count the columns in tables in the Database, so I am still figure how to create variable word through loop to allow equalized from $_post as if $_post appear in two or three or four...I figured out to set up the $_post in loop, but I haven't find a way to have create new variable to equalized with $_post in loop in same time. here my code <!doctype html> <html> <head> <title>Add name and number</title> <link href="defaultdatabase.css" rel="stylesheet" type="text/css"> </head> <h2>Add any DSDJ information to database</h2> <?php require ("require2.php"); $sql = "show tables from NewDSDJ"; $list = mysqli_query($GaryDB, $sql); while ($row = mysqli_fetch_array($list)) { $table[] = $row[0]; $option = ''; foreach ($table as $rows) { $option .= "<option value='{$rows}'>{$rows}</option>"; } } ?> <form action="addname.php" method="post"> <table> <tr><th>Select the table</td><td> <select name="subject"> <?php echo $option; ?> </select></td><td><input type="submit" name="selected" value="select"></td></tr> </table> </form> <form> <table> <?php if (isset($_POST['selected'])) { $selected = $_POST['subject']; $column = "select column_name from information_schema.columns where table_name = '" . $selected . "'"; $list5 = mysqli_query($GaryDB, $column); while ($array = mysqli_fetch_array($list5)) { $input = ''; foreach ($array as $row5) { $input = "<tr><td>{$row5}:</td><td colspan='2'><input type='text' name='label[]'></td></tr>"; } echo $input; } if (isset($_POST['insert'])) { foreach ($array as $row6) { $ins = "{$row6},"; } for ($i = 0; $i < count($array); $i++) { $label = $_POST['label']; } echo $label; $insert = "insert into " . $selected . " (" . $ins . ") values (" . $label . ")"; mysqli_query($GaryDB, $insert) or die("Could not insert"); } }echo "<tr><td><input type='submit' name='insert'></td></tr>"; mysqli_close($GaryDB); ?> </table> </form> </html> Look at above of $insert, that is one I haven't figure how to create variable word to get data from name in form in HTML. Can you help? Thanks, Gary Taylor
  24. emcy

    php NOT words?

    Hi, I am working on a simple login for just 1 person.. me .. to be able to update my blog online. I would like to have the login button on the blog page itself. I currently have it set up as a modal. I have the database setup for 4 columns - ID, date, title, content and signedby I have the form page set up as well (blog.php), and the database access dbconfig.php file is written also. 1. - wrote up the modal button so that when I click on the login/submit button it should call up pswchecking.php to verify that the username and password are me only, and that if it is true, then it will pop up the blog entry page which then enters the new entries into the database in mysqli. (how do I write pswchecking.php? - I looked at Mysqli code in w3schools, and php and ajax. I could maybe do it as a php/ajax file but then the text file can be found by a search on google, how do I hide it? So then I thought maybe to do a database with just one user in it.. me that felt like overkill.. not sure.. ideas? After that, I want to automatically be able to post the new blog entries from the database to the blog.php page automatically. I would also like it sorted by year and month links so they don't get all the records downloaded, and it only shows the latest post. To say the least, I would not be posting if it worked like a charm . It doesn't work and I get error messages... current code I have is as such: 1. blog.php page with a login modal button . <!-- Modal Content --> <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // where blogdbConfig.php is //<?php // got this info from 1and1.com directly //$host_name = "dbnumber.db.1and1.com"; // $user_name = "dbonumber"; // $password = "password"; // $database = "dbnumber"; // Create connection using the mysqli procedural format //$connect = mysqli_connect($host_name, $user_name, $password, $database); // Check connection // if (!$connect) { // die("Connection failed: " . mysqli_connect_error()); // } // ?> //***********NOW THAT IT'S CONNECTED TO THE DATABASE I WANT IT TO POP UP A PAGE CALLED blogentriespage.php SO I CAN MAKE A NEW DATABASE ENTRY. //DO I USE AN INCLUDE STATMENT HERE? SUCH AS THE FOLLOWING, AND HOW DO I PUT IT ON A POP-UP PAGE? //<?php //include('blogentriespage.php'); //?> // where blogentries.php is: // <?php //keep this in here to display all the errors on debugging // ini_set('display_errors', 1); // error_reporting(E_ALL); // include('blogdbConfig.php'); // $connect = mysqli_connect($host_name, $user_name, $password, $database); // if (!$connect) { // die("Connection failed: " . mysqli_connect_error()); // } // function test_input($data) { // $data = trim($data); // $data = stripslashes($data); // $data = htmlspecialchars($data); // return $data; // } // $dateErr = $titleErr = $contentErr = $signedbyErr = ""; // $date = $title = $content = $signedby = ""; // if ($_SERVER["REQUEST_METHOD"] == "POST") { // $passed = true; // if (empty($_POST["date"])) { // $dateErr = "Please enter a date in the format of monthname date, full year"; // $passed = false; // } else { // $date = test_input($_POST["date"]); // } // if (empty($_POST["title"])) { // $titleErr = "Title is required"; // $passed = false; // } else { // $title = test_input($_POST["title"]); // if (!preg_match("/^[a-zA-Z ]*$/",$title)) { // $passed = false; // $titleErr = "Only letters and white space allowed"; // } // } // if (empty($_POST["content"])) { // $contentErr = "Content is required"; // $passed = false; // } else { // $content = test_input($_POST["content"]); // } // if (empty($_POST["signedby"])) { // $signedbyErr = "Signed by is required"; // $passed = false; // } else { // $signedby = test_input($_POST["signedby"]); // if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { // $passed = false; // $signedbyErr = "Only letters and white space allowed"; // } // } // if ($passed) { // $mysqli = "INSERT INTO xmasblogentries (date, title, content, signedby) VALUES ('$date','$title','$content','$signedby')"; // if (mysqli_query($connect, $mysqli)) { // echo "New record created successfully"; // } else { // echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); // } // $email = "info@me.com"; // $emailSubject = "A new blog entry was just received in the database"; // $headers = "From:$signedby\r\n"; // $headers = "Content-type: text/html\r\n"; // $body = <<<EOD // <br><hr><br> // Date : $date <br> // Title : $title <br> // Content : $content <br> // Signed By : $signedby <br> // EOD; // $success = mail($email, $emailSubject, $body, $headers); // echo "<h2>Thank you your new blog entry was received successfully. Here is a copy of what you wrote:</h2>"; // echo "Date: " . $date . "<br>"; // echo "Title: " . $title . "<br>"; // echo "Content: " . $content . "<br>"; // echo "Signed By: " . $signedby . "<br>"; // $date = $title = $content = $signedby = ""; // } // } // ?> // <p><span class="error">* required field.</span></p> // <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded"> // Date:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Date" name="date" value="<?php echo $date; ?>"><span class="error">* <?php echo $dateErr; ?></span><br> // Title:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Title" required name="title" value="<?php echo $title; ?>"><span class="error">* <?php echo $titleErr; ?></span><br> // Content:<textarea placeholder="Content" required name="content" rows="30" cols="40" value="<?php echo $content; ?>"></textarea><span class="error">* <?php echo $contentErr; ?></span><br> // Signed By:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Signed By" required name="signedby" value="<?php echo $signedby; ?>"><span class="error">* <?php echo $signedbyErr; ?></span><br> // <input class="w3-input w3-padding-16 w3-border" type="datetime-local" required name="date" value="2017-11-16T20:00"> // <br> // <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> // </form> // <?php // mysqli_close($connect); // ?> // </div> //SECTION C // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // set all the fields on the new database record to empty initially to reset it from the previous entry // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C //This tells the server what to do with the entry info when it gets to the SECTION D of this php page // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } // then start working on the user's info to clean it up and make sure all the fields have been filled in if (empty($_POST["date"])) { $dateErr = "Please enter a date in the format of monthname date, full year"; $passed = false; } else { $date = test_input($_POST["date"]); } if (empty($_POST["title"])) { $titleErr = "Title is required"; $passed = false; } else { $title = test_input($_POST["title"]); if (!preg_match("/^[a-zA-Z ]*$/",$title)) { $passed = false; $titleErr = "Only letters and white space allowed"; } } if (empty($_POST["content"])) { $contentErr = "Content is required"; $passed = false; } else { $content = test_input($_POST["content"]); } if (empty($_POST["signedby"])) { $signedbyErr = "Signed by is required"; $passed = false; } else { $signedby = test_input($_POST["signedby"]); if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { $passed = false; $signedbyErr = "Only letters and white space allowed"; } } if ($passed) { //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code above) $stmt = $mysqli->prepare("INSERT INTO xmasblogentries (date, title, content, signedby) VALUES (':date',':title',':content',':signedby')"); $stmt->bindParam(':date', $txtdate); $stmt->bindParam(':title', $txttitle); $stmt->bindParam(':content', $txtcontent); $stmt->bindParam(':signedby', $txtsignedby); $stmt->execute(); //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know someone just posted something. $email = "info@me.com"; $emailSubject = "A new blog entry was just received in the database"; // define what the headers of the email should say $headers = "From:$signedby\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> Date : $date <br> Title : $title <br> Content : $content <br> Signed By : $signedby <br> EOD; $success = mail($email, $emailSubject, $body, $headers); // SECTION I // on this same user's page on his computer in the browser window, next, print on screen a copy of what the user entered above echo "<h2>Thank you your new blog entry was received successfully. Here is a copy of what you wrote:</h2>"; echo "Date: " . $date . "<br>"; echo "Title: " . $title . "<br>"; echo "Content: " . $content . "<br>"; echo "Signed By: " . $signedby . "<br>"; $date = $title = $content = $signedby = ""; } } ?> <form class="modal-content animate" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded">> <div class="imgcontainer"> <img src="http://www.me.com/pagepieces/images/me.png" alt="Avatar" width="150" height="100" class="avatar"> </div> <div class="container"> <label for="uname"><b>Username</b></label> <input type="text" placeholder="Enter Username" name="uname" required> <label for="psw"><b>Password</b></label> <input type="password" placeholder="Enter Password" name="psw" required> <button type="submit" name="submit" value="Submit">Login</button> </div> <div class="container" style="background-color:#f1f1f1"> <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button> </div> </form> <?php mysqli_close($connect); ?> </div> <script> // Get the modal var modal = document.getElementById('id01'); // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script> 2. I would like to make it so that when I click on the "submit" button, that it first checks to see if I have entered the correct user name and password info (do I need to make a php file such as pswchecking.php or do this in a new database for only 1 user name?) and that if it isn't me, then it sends an error message - This is what I have written up from my mixed limited understanding of javascript, php, html, etc... (note I am also getting an error in Dreamweaver on the "die("you are NOT Me You cannot access this database"; line - why? Also.. where to place the "include" for this php page? Does it go on the modal before or after the submit button? <?php $user_name = "me"; $password = "mysetpasword"; // Check connection if (!$user_name . !$password) { die("You are NOT Me You cannot access this database"; } ?> 3. Then, if it is me, to give a success message <?php $user_name = "myword"; $password = "mypasword"; // Check connection if (!$user_name, !$password) { die("You are NOT Me! You cannot access this database " . mysqli_connect_error()); } } else { echo "Hi Me! Welcome Back! "; } ?> 4. And to pop up the blog.php page to enter a new blog entry on (how do I make it be a pop window? if its in the middle of the coding?) <?php $user_name = "myword"; $password = "mypasword"; // Check connection if (!$user_name, !$password) { die("You are NOT Me! You cannot access this database " . mysqli_connect_error()); } } else { echo "Hi Me! Welcome Back! " . include('blogentrypage.php'); } ?> 5. This is the blog entry page <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous entry $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } // then start working on the entry info to clean it up and make sure all the fields have been filled in if (empty($_POST["date"])) { $dateErr = "Please enter a date in the format of monthname date, full year"; $passed = false; } else { $date = test_input($_POST["date"]); } if (empty($_POST["title"])) { $titleErr = "Title is required"; $passed = false; } else { $title = test_input($_POST["title"]); if (!preg_match("/^[a-zA-Z ]*$/",$title)) { $passed = false; $titleErr = "Only letters and white space allowed"; } } if (empty($_POST["content"])) { $contentErr = "Content is required"; $passed = false; } else { $content = test_input($_POST["content"]); } if (empty($_POST["signedby"])) { $signedbyErr = "Signed by is required"; $passed = false; } else { $signedby = test_input($_POST["signedby"]); if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { $passed = false; $signedbyErr = "Only letters and white space allowed"; } } if ($passed) { //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code below) $mysqli = "INSERT INTO blogentries (date, title, content, signedby) VALUES ('$date','$title','$content','$signedby')"; //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know I just posted something. $email = "info@me.com"; $emailSubject = "A new blog entry was just received in the database"; // define what the headers of the email should say $headers = "From:$signedby\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> Date : $date <br> Title : $title <br> Content : $content <br> Signed By : $signedby <br> EOD; // SECTION H // define the action to take upon success of a new record having been created - i.e. mail it with the email info, email subject, body, and headers from the above definitions, to my email address $success = mail($email, $emailSubject, $body, $headers); // SECTION I // on this same page on the computer in the browser window, next, print on screen a copy of what was entered echo "<h2>Thank you your new blog entry was received successfully. Here is a copy of what you wrote:</h2>"; echo "Date: " . $date . "<br>"; echo "Title: " . $title . "<br>"; echo "Content: " . $content . "<br>"; echo "Signed By: " . $signedby . "<br>"; // SECTION J // when everything has been done, close the database connection $date = $title = $content = $signedby = ""; } } ?> <p><span class="error">* required field.</span></p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded"> Date:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Date" name="date" value="<?php echo $date; ?>"><span class="error">* <?php echo $dateErr; ?></span><br> Title:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Title" required name="title" value="<?php echo $title; ?>"><span class="error">* <?php echo $titleErr; ?></span><br> Content:<textarea placeholder="Content" required name="content" rows="30" cols="40" value="<?php echo $content; ?>"></textarea><span class="error">* <?php echo $contentErr; ?></span><br> Signed By:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Signed By" required name="signedby" value="<?php echo $signedby; ?>"><span class="error">* <?php echo $signedbyErr; ?></span><br> <input class="w3-input w3-padding-16 w3-border" type="datetime-local" required name="date" value="2017-11-16T20:00"> <!--- PLACEHOLDER Not allowed on this type ABOVE--> <br> <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> </form> <?php mysqli_close($connect); ?> 6. Next, when I have finished entering the information for the new entry, and click submit - it goes to a Config.php file to access the database and put the info into it <?php // got this info from 1and1.com directly $host_name = "me.db.1and1.com"; $user_name = "medatabaseusername"; $password = "mydatabasepsassword"; $database = "mydatabase"; // Create connection using the mysqli procedural format $connect = mysqli_connect($host_name, $user_name, $password, $database); // Check connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } ?> I have the entry page setup to send me a confirmation email with the new entry info. The final step is to add the information for the new posting only, on the blog.php page, as well as links to years and months for all the other postings , so not all the entries are shown at once. <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous entry $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } // then start working on the entry info to clean it up and make sure all the fields have been filled in if (empty($_POST["date"])) { $dateErr = "Please enter a date in the format of monthname date, full year"; $passed = false; } else { $date = test_input($_POST["date"]); } if (empty($_POST["title"])) { $titleErr = "Title is required"; $passed = false; } else { $title = test_input($_POST["title"]); if (!preg_match("/^[a-zA-Z ]*$/",$title)) { $passed = false; $titleErr = "Only letters and white space allowed"; } } if (empty($_POST["content"])) { $contentErr = "Content is required"; $passed = false; } else { $content = test_input($_POST["content"]); } if (empty($_POST["signedby"])) { $signedbyErr = "Signed by is required"; $passed = false; } else { $signedby = test_input($_POST["signedby"]); if (!preg_match("/^[a-zA-Z ]*$/",$signedby)) { $passed = false; $signedbyErr = "Only letters and white space allowed"; } } if ($passed) { //SECTION E // define what $mysqli is made up of (taken from the fields in the html form code below) $mysqli = "INSERT INTO blogentries (date, title, content, signedby) VALUES ('$date','$title','$content','$signedby')"; //SECTION F // Checking the connection and verifying the user's information/$mysqli (which was defined above) has been entered into the new record in the database, then it gives a success message if (mysqli_query($connect, $mysqli)) { echo "New record created successfully"; } else { echo "Error: " . $mysqli . "<br>" . mysqli_error($connect); } // SECTION G // define what $email, and $email Subject is made up of for when it sends an email to me to let me know I just posted something. $email = "info@me.com"; $emailSubject = "A new blog entry was just received in the database"; // define what the headers of the email should say $headers = "From:$signedby\r\n"; $headers = "Content-type: text/html\r\n"; // define what the body of the email should say and look like $body = <<<EOD <br><hr><br> Date : $date <br> Title : $title <br> Content : $content <br> Signed By : $signedby <br> EOD; // SECTION H // define the action to take upon success of a new record having been created - i.e. mail it with the email info, email subject, body, and headers from the above definitions, to my email address $success = mail($email, $emailSubject, $body, $headers); // SECTION I // setup a new link on the blog page for the category under which it falls (i.e. year/month/date) //i.e if a new database record was created, then post the new link on the blog page by category under year and month and date ( so it needs to be sorted in order), and show only the fresh content via an "echo" command? //HOW!?!?!???! // SECTION J // when everything has been done, close the database connection $date = $title = $content = $signedby = ""; } } ?> <p><span class="error">* required field.</span></p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="application/x-www-form-urlencoded"> Date:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Date" name="date" value="<?php echo $date; ?>"><span class="error">* <?php echo $dateErr; ?></span><br> Title:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Title" required name="title" value="<?php echo $title; ?>"><span class="error">* <?php echo $titleErr; ?></span><br> Content:<textarea placeholder="Content" required name="content" rows="30" cols="40" value="<?php echo $content; ?>"></textarea><span class="error">* <?php echo $contentErr; ?></span><br> Signed By:<input class="w3-input w3-padding-16 w3-border" type="text" placeholder="Signed By" required name="signedby" value="<?php echo $signedby; ?>"><span class="error">* <?php echo $signedbyErr; ?></span><br> <input class="w3-input w3-padding-16 w3-border" type="datetime-local" required name="date" value="2017-11-16T20:00"> <!--- PLACEHOLDER Not allowed on this type ABOVE--> <br> <button class="w3-button w3-black"><input type="submit" name="submit" value="Submit"></button> </form> <?php mysqli_close($connect); ?> where blogsortedlinks.php is used to sort the information before posting it on the blog.php page: <?php //keep this in here to display all the errors on debugging ini_set('display_errors', 1); error_reporting(E_ALL); // SECTION A // define the connection info // got this info from 1and1.com directly include('blogdbConfig.php'); // Define the connection and then connect $connect = mysqli_connect($host_name, $user_name, $password, $database); // this is where the debugging portion ends /// set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) // SECTION B // check the connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } // SECTION C //This tells the server what to do with the user's info when it gets to the SECTION D of this php page (I suspect this should be after the SECTION D but then SECTION E of defining mysqli will have to be moved down further as well) // test again and strip the user info of characters I don't want function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } // set all the fields on the new database record to empty initially to reset it from the previous user (do I need to autoincrement here somewhere? Maybe my database settings are wrong?) $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info.... $passed = true; // } else { $passed = false; } if ($passed) { // I have a MySQL database with which I'm dynamically populating a web page. I'm building a MySQL query that fetches some dates stored in a table called blogentries that I can later echo out on the blog page with PHP. The columns in that table are id, date, title, content, and signedby. I want the user to be able to sort dates and titles alphabetically, by date (low-high) etc by clicking the relevant links on the page. This is what I've written so far: // Run a SELECT query to get all the dates that are stored in the database // By default, if no sorting URL variable is fed onto the page, then the SQL query becomes order by id. // The first time you land on the blog page as plain blog.php, not blog.php?=variable, this is the query that's used $mysqli = mysqli_query($connect,"SELECT * FROM blogentries ORDER BY date DESC"); // If the user chooses to sort the dates in a different way, then an HTML link will set a PHP variable onto this blog page // We will check for that variable and change the SQL query to sort the dates in a different way if (isset($_GET['sortby'])) { // Capture that in a variable by that name $sortby == $_GET['sortby']; // Now to change the SQL query based on the sorting the user chose (date high to low, low to high, alphabetical and latest first) if ($sortby == 'datehilo') { $mysqli = mysqli_query($connect,"SELECT * FROM date ORDER BY title DESC"); } elseif ($sortby = 'datelohi') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title ASC"); } elseif ($sortby = 'title') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title"); } } <p><a href="blog.php?sortby=datehilo">Date (Highest-Lowest)</a></p> <p><a href="blog.php?sortby=datelohi">Date (Lowest-Highest)</a></p> <p><a href="blog.php?sortby=title">Alphabetical</a></p> ?> sortedlinks.php is: <?php ini_set('display_errors', 1); error_reporting(E_ALL); include('blogdbConfig.php'); $connect = mysqli_connect($host_name, $user_name, $password, $database); if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $dateErr = $titleErr = $contentErr = $signedbyErr = ""; $date = $title = $content = $signedby = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $passed = true; // } else { $passed = false; } if ($passed) { $mysqli = mysqli_query($connect,"SELECT * FROM blogentries ORDER BY date DESC"); // I copied the folowing code from somewhere else and am wondering if I need to make abother php page or something that identifies the variables sortby, datehilo, datelohi, title - seems to me this coudl just be done on the mysqli database itself ? // If the user chooses to sort the dates in a different way, then an HTML link will set a PHP variable onto this blog page // We will check for that variable and change the SQL query to sort the dates in a different way if (isset($_GET['sortby'])) { // Capture that in a variable by that name $sortby == $_GET['sortby']; // Now to change the SQL query based on the sorting the user chose (date high to low, low to high, alphabetical and latest first) if ($sortby == 'datehilo') { $mysqli = mysqli_query($connect,"SELECT * FROM date ORDER BY title DESC"); } elseif ($sortby = 'datelohi') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title ASC"); } elseif ($sortby = 'title') { $mysqli == mysqli_query($connect,"SELECT * FROM date ORDER BY title"); } } include('blogentryretrieval.php'); <p><a href="blog.php?sortby=datehilo">Date (Highest-Lowest)</a></p> <p><a href="blog.php?sortby=datelohi">Date (Lowest-Highest)</a></p> <p><a href="blog.php?sortby=title">Alphabetical</a></p> ?> and finally blogentryretrieval.php <?php // got this info from 1and1.com directly $host_name = "dbnumber.db.1and1.com"; $user_name = "dbonumber"; $password = "password"; $database = "dbnumber"; // Create connection using the mysqli procedural format $connect = mysqli_connect($host_name, $user_name, $password, $database); // Check connection if (!$connect) { die("Connection failed: " . mysqli_connect_error()); } $mysqli = "SELECT date, title, content, signedby FROM blogentries"; $result = $connect->query($mysqli); if ($result->num_rows > 0) { echo "<table><tr><th>Date</th><th>Title</th><th>Content</th><th>Written by:</th></tr>"; // output data of each row while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["date"]. "</td><td>" . $row["title"]. "</td><td> " . $row["content"]. "</td><td>" . $row["signedby"]. "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } $connect->close(); ?> The error messages I am getting are as follows: on the blog.php page when I call it up initially it says this: Warning: include(blogsortedlinks): failed to open stream: No such file or directory in /homepages/42/htdocs/blog.php on line 375Warning: include(): Failed opening 'blogsortedlinks' for inclusion (include_path='.:/usr/lib/php5.6') in /homepages/42/htdocs/blog.php on line 375Date: Notice: Undefined index: date in /homepages/42/htdocs/blog.php on line 378Title: Notice: Undefined index: title in /homepages/42/htdocs/blog.php on line 379Content: Notice: Undefined index: content in /homepages/42/htdocs/blog.php on line 380Author: Notice: Undefined index: signedby in /homepages/42/htdocs/blog.php on line 381 When I click on the login button.. it calls up the modal fine....but.. it disappears when I click on submit and doesn't do anything.... I also don't know where to put my username and password in a database or on a separate php file to sore it permanently so the modal can call on it to verify I am the right person ....ideas? Thanks B
  25. honkmaster

    Calculate Total hours and Mins (over 24)

    Hi I need to display total hours and mins as this example "35 Hrs 23 Mins", issue I'm having is after 24 it goes back to zero I'm storing the time as follows 127380 (seconds) I should get 35:23 but I'm getting 59:23 ??? Any ideas would help $date = '127380'; $minsec = gmdate("i:s", $date); $hours = gmdate("d", $date)*24 + gmdate("H", $date); echo $time = $hours . ':' . $minsec;
×