Jump to content

SalientAnimal

Members
  • Posts

    366
  • Joined

  • Last visited

Everything posted by SalientAnimal

  1. Hi All, I need some help with my forms submit page. I can not understand why I am getting the error message saying: Notice: Undefined variable: stmt in C:\mydirectory\process\submit_sales_retentions.php on line 84 Fatal error: Call to a member function close() on a non-object in C:\mydirectory\process\submit_sales_retentions.php on line 84 <?php include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; include_once '../includes/formatting.php'; ini_set('display_errors',1); error_reporting(E_ALL); if (isset( $_POST['username'] , $_POST['sales_reference'] , $_POST['msisdn'] , $_POST['sale_type'] )) { // SANITIZE AND VALIDATE THE DATA BEING PROCESSED BY THE FORM $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING); $sales_reference = filter_input(INPUT_POST, 'sales_reference', FILTER_SANITIZE_STRING); $msisdn = filter_input(INPUT_POST, 'msisdn', FILTER_SANITIZE_STRING); $sale_type = filter_input(INPUT_POST, 'sale_type', FILTER_SANITIZE_STRING); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if (empty($error_msg)) { // INSERT THE NEW FOR INFORMATION INTO THE DATABASE TABLE if ($insert_stmt = $mysqli->prepare(" INSERT INTO usr_retentions_sales ( username , sales_reference , msisdn , sale_type ) VALUES (?, ?, ?, ?)")) { $insert_stmt->bind_param( 'ssss' , $username , $sales_reference , $msisdn , $sale_type ); // EXECUTE THE PREPARED QUERY if (! $insert_stmt->execute()) //PRINT THE NUMBERS OF ROWS THAT HAVE BEEN AFFECTED { header('Location: ../errors/errorduplicate.php?err=errormessage Error: Please note that you may only complete the form once.'); exit; } include "../success/sales_retentions_success.php"; exit; } /* CLOSE THE STATEMENT */ $stmt->close(); /* CLOSE THE CONNECTION */ $mysqli->close(); } } ?> Please can someone help with the cause of this error, and how to fix it, thanks.
  2. It doesn't save me time no, but it allows me to finish off some things (although not 100%). I then have an idea of what can / can't be done and I look for better ways of doing it. I know this is not the best approach, but unfortunately my job profile isn't focused on coding. It is merely a nice to have that I use to implement a few things. This is why I have to try and learn / improve on these over weekends at home when I have a quite weekend. I really appreciate all the info / feedback that you giving Jacques1, and I will certainly use these tips to try and improve on my current way of doing things.
  3. Had my where clause in the wrong place of my UNION query, silly mistake.
  4. Not at all what I was implying Jacques1. The reason my main focus is not on the security is because of the short space of time in which I need to produce the screens that I am creating. Thus, yes I agree the quality and correctness is of high importance, but this is something I am working on in my own time and then as I learn the better / correct methods I do implement them. What I am merely saying is that because of the short time I have to finish some projects, I often try to get them working with the minimum fuss and later I improve on them. For me PHP has been an entirely self learning experience and that ca make it a little difficult to get the exact concepts / principles working correctly. The code I have for the drop down menu looks like the below: //FUNCTION TO CREATE HTML FOR OPTIONS LIST function createOptions($optionList, $selectedValue) { $options = ''; foreach ($optionList as $option) { $selected = ($option['value']==$selectedValue) ? ' selected="selected"' : ''; $options .= "<option value='{$option['value']}'{$selected}>{$option['label']}</option>\n"; } return $options; } if ( isset ( $_GET['department'] ) && is_numeric ( $_GET['department'] ) ){ // There's a department=xxx in the querystring so we use that as the select's default value $default_value = $_GET['department']; } else { // There's no department=xxx in the querystring so we can assign a default value here like so $default_value = 7; } $department = isset($default_value) ? intval($default_value) : false; //GENERATE OPTIONS FOR PRIMARY CATEGORY $sql_1 = "SELECT DISTINCT department_id AS value, department AS label FROM sys_departments ORDER BY department"; $optionList = $dbo->query($sql_1); $department_options = createOptions($optionList, $department); <script language="javascript"> function getSelectValue(selectID) { var optionObj = document.getElementById(selectID); return optionObj.options[optionObj.selectedIndex].value; } function reload(form) { //Adding the unselected options should work fine var locationURL = 'graph2.php'; locationURL += '?department=' + getSelectValue('department'); //Perform the reload self.location = locationURL; } </script> Creating the drop-down <select name='department' id='department' onChange="reload(this.form)"> <option value=''>Select one</option> <?php echo $department_options; ?> </select>
  5. Thanks for this Jacques1, luckily my site is not exposed to the entire WWW, so having the best security isn't my biggest concern at this point. Although yes I agree, it is something I need to learn a lot about especially if I want to develop sites that I will eventually publish to the WWW. I also want to say thanks for everyone else for their input on this thread, and I was able to come up with a solution. Ch0cu3r, I actually later realised that I had the field category in my select query and is was a matter of adding to my graph code. I have to adjust my query to name the column as categoryField, and then it all worked. So now I want to take the next step in making my graph even more dynamic. In the past I've used a drop-down list for the user to make a selection, and this has really worked nicely, and I would like to do the same, however, the onchange event does not seem to work here. Any advice? I can post code if need be? Basically my Query will have a WHERE clause... Something like WHERE department_id = $department.
  6. Fixed the Dissatisfied, it was a typo. Working on populating the bottom axis.
  7. Ok cool, so I have it populating but with a few challenges. 1. My one column is not showing. i.e Dissatisfied 2. The headings at the bottom are all coming up as undefined. This is what it looks like now. <?php // get the records from the database if ($result = $mysqli->query("SELECT * FROM (SELECT COUNT(CASE WHEN question_1 = 0 THEN 1 ELSE NULL END)/ COUNT(question_1)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_1 = 1 THEN 1 ELSE NULL END)/ COUNT(question_1)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_1 = 2 THEN 1 ELSE NULL END)/ COUNT(question_1)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_1 = 3 THEN 1 ELSE NULL END)/ COUNT(question_1)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_2 = 0 THEN 1 ELSE NULL END)/ COUNT(question_2)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_2 = 1 THEN 1 ELSE NULL END)/ COUNT(question_2)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_2 = 2 THEN 1 ELSE NULL END)/ COUNT(question_2)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_2 = 3 THEN 1 ELSE NULL END)/ COUNT(question_2)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_3 = 0 THEN 1 ELSE NULL END)/ COUNT(question_3)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_3 = 1 THEN 1 ELSE NULL END)/ COUNT(question_3)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_3 = 2 THEN 1 ELSE NULL END)/ COUNT(question_3)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_3 = 3 THEN 1 ELSE NULL END)/ COUNT(question_3)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_4 = 0 THEN 1 ELSE NULL END)/ COUNT(question_4)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_4 = 1 THEN 1 ELSE NULL END)/ COUNT(question_4)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_4 = 2 THEN 1 ELSE NULL END)/ COUNT(question_4)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_4 = 3 THEN 1 ELSE NULL END)/ COUNT(question_4)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_5 = 0 THEN 1 ELSE NULL END)/ COUNT(question_5)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_5 = 1 THEN 1 ELSE NULL END)/ COUNT(question_5)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_5 = 2 THEN 1 ELSE NULL END)/ COUNT(question_5)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_5 = 3 THEN 1 ELSE NULL END)/ COUNT(question_5)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_6 = 0 THEN 1 ELSE NULL END)/ COUNT(question_6)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_6 = 1 THEN 1 ELSE NULL END)/ COUNT(question_6)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_6 = 2 THEN 1 ELSE NULL END)/ COUNT(question_6)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_6 = 3 THEN 1 ELSE NULL END)/ COUNT(question_6)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_7 = 0 THEN 1 ELSE NULL END)/ COUNT(question_7)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_7 = 1 THEN 1 ELSE NULL END)/ COUNT(question_7)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_7 = 2 THEN 1 ELSE NULL END)/ COUNT(question_7)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_7 = 3 THEN 1 ELSE NULL END)/ COUNT(question_7)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_8 = 0 THEN 1 ELSE NULL END)/ COUNT(question_*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_8 = 1 THEN 1 ELSE NULL END)/ COUNT(question_*100 AS 'Satisfied' ,COUNT(CASE WHEN question_8 = 2 THEN 1 ELSE NULL END)/ COUNT(question_*100 AS 'Dissatified' ,COUNT(CASE WHEN question_8 = 3 THEN 1 ELSE NULL END)/ COUNT(question_*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_9 = 0 THEN 1 ELSE NULL END)/ COUNT(question_9)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_9 = 1 THEN 1 ELSE NULL END)/ COUNT(question_9)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_9 = 2 THEN 1 ELSE NULL END)/ COUNT(question_9)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_9 = 3 THEN 1 ELSE NULL END)/ COUNT(question_9)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_10 = 0 THEN 1 ELSE NULL END)/ COUNT(question_10)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_10 = 1 THEN 1 ELSE NULL END)/ COUNT(question_10)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_10 = 2 THEN 1 ELSE NULL END)/ COUNT(question_10)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_10 = 3 THEN 1 ELSE NULL END)/ COUNT(question_10)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_11 = 0 THEN 1 ELSE NULL END)/ COUNT(question_11)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_11 = 1 THEN 1 ELSE NULL END)/ COUNT(question_11)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_11 = 2 THEN 1 ELSE NULL END)/ COUNT(question_11)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_11 = 3 THEN 1 ELSE NULL END)/ COUNT(question_11)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_12 = 0 THEN 1 ELSE NULL END)/ COUNT(question_12)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_12 = 1 THEN 1 ELSE NULL END)/ COUNT(question_12)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_12 = 2 THEN 1 ELSE NULL END)/ COUNT(question_12)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_12 = 3 THEN 1 ELSE NULL END)/ COUNT(question_12)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_13 = 0 THEN 1 ELSE NULL END)/ COUNT(question_13)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_13 = 1 THEN 1 ELSE NULL END)/ COUNT(question_13)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_13 = 2 THEN 1 ELSE NULL END)/ COUNT(question_13)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_13 = 3 THEN 1 ELSE NULL END)/ COUNT(question_13)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_14 = 0 THEN 1 ELSE NULL END)/ COUNT(question_14)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_14 = 1 THEN 1 ELSE NULL END)/ COUNT(question_14)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_14 = 2 THEN 1 ELSE NULL END)/ COUNT(question_14)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_14 = 3 THEN 1 ELSE NULL END)/ COUNT(question_14)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014 UNION ALL SELECT COUNT(CASE WHEN question_15 = 0 THEN 1 ELSE NULL END)/ COUNT(question_15)*100 AS 'Very Satisfied' ,COUNT(CASE WHEN question_15 = 1 THEN 1 ELSE NULL END)/ COUNT(question_15)*100 AS 'Satisfied' ,COUNT(CASE WHEN question_15 = 2 THEN 1 ELSE NULL END)/ COUNT(question_15)*100 AS 'Dissatified' ,COUNT(CASE WHEN question_15 = 3 THEN 1 ELSE NULL END)/ COUNT(question_15)*100 AS 'Very Dissatisfied' FROM svy_climate_may_2014) svy_result")); $arr = array(); while($row = mysqli_fetch_assoc($result)) { $arr[] = $row; } if($arr) { $json = json_encode($arr); // json encode the array } ?> <html> <head> <title>Climate Survey Results</title> <!-- amCharts javascript sources --> <script type="text/javascript" src="http://cdn.amcharts.com/lib/3/amcharts.js"></script> <script type="text/javascript" src="http://cdn.amcharts.com/lib/3/serial.js"></script> <!-- amCharts javascript code --> <script type="text/javascript"> AmCharts.makeChart("chartdiv", { "type": "serial", "categoryField": "category", "angle": 45, "depth3D": 10, "startDuration": 0.5, "theme": "default", "categoryAxis": { "gridPosition": "start" }, "trendLines": [], "graphs": [ { "fillAlphas": 1, "fillColors": "#008000", "id": "very_satisfied", "lineColor": "#008000", "title": "Very Satisfied", "type": "column", "valueField": "Very Satisfied" }, { "fillAlphas": 1, "fillColors": "#0000FF", "id": "satisfied", "lineColor": "#0000FF", "title": "Satisfied", "type": "column", "valueField": "Satisfied" }, { "fillAlphas": 1, "fillColors": "#FF8000", "fontSize": 0, "id": "dissatisfied", "lineColor": "#FF8000", "title": "Dissatisfied", "type": "column", "valueField": "Dissatisfied" }, { "fillAlphas": 1, "fillColors": "#CC0000", "id": "very_dissatisfied", "lineColor": "#CC0000", "title": "Very Dissatisfied", "type": "column", "valueField": "Very Dissatisfied" } ], "guides": [], "valueAxes": [ { "id": "ValueAxis-1", "stackType": "100%", "title": "Percentage Scored (%)" } ], "allLabels": [], "balloon": {}, "legend": { "textClickEnabled": false, "useGraphSettings": false, "valueAlign": "centre" }, "titles": [ { "size": 20, "text": "Climate Survey Results" } ], "dataProvider": <?php echo json_encode($arr); ?>, } ); </script> </head> <body> <div id="chartdiv" style="width: 50%; height: 400px; " ></div> </body> </html> I am also still trying to figure it out myself, but would appreciate if someone has some time to take a look. Thanks.
  8. Hi All, I have a AmChart file, but unfortunately this data is static. I would like to make this data more dynamic by populating it from a PHP file. Please can someone direct me in doing this? Here is the AmChart page Code: <!DOCTYPE html> <html> <head> <title>Climate Survey Results</title> <!-- amCharts javascript sources --> <script type="text/javascript" src="http://cdn.amcharts.com/lib/3/amcharts.js"></script> <script type="text/javascript" src="http://cdn.amcharts.com/lib/3/serial.js"></script> <!-- amCharts javascript code --> <script type="text/javascript"> AmCharts.makeChart("chartdiv", { "type": "serial", "categoryField": "category", "angle": 45, "depth3D": 10, "startDuration": 0.5, "theme": "default", "categoryAxis": { "gridPosition": "start" }, "trendLines": [], "graphs": [ { "fillAlphas": 1, "fillColors": "#008000", "id": "very_satisfied", "lineColor": "#008000", "title": "Very Satisfied", "type": "column", "valueField": "Very Satisfied" }, { "fillAlphas": 1, "fillColors": "#0000FF", "id": "satisfied", "lineColor": "#0000FF", "title": "Satisfied", "type": "column", "valueField": "Satisfied" }, { "fillAlphas": 1, "fillColors": "#FF8000", "fontSize": 0, "id": "dissatisfied", "lineColor": "#FF8000", "title": "Dissatisfied", "type": "column", "valueField": "Dissatisfied" }, { "fillAlphas": 1, "fillColors": "#CC0000", "id": "very_dissatisfied", "lineColor": "#CC0000", "title": "Very Dissatisfied", "type": "column", "valueField": "Very Dissatisfied" } ], "guides": [], "valueAxes": [ { "id": "ValueAxis-1", "stackType": "100%", "title": "Percentage Scored (%)" } ], "allLabels": [], "balloon": {}, "legend": { "textClickEnabled": false, "useGraphSettings": false, "valueAlign": "centre" }, "titles": [ { "size": 20, "text": "Climate Survey Results" } ], "dataProvider": [ { "category": "1", "Very Satisfied": 4.69, "Satisfied": 65.63, "Dissatisfied": 23.43, "Very Dissatisfied": 6.25 }, { "category": "2", "Very Satisfied": 3.13, "Satisfied": 46.88, "Dissatisfied": 34.37, "Very Dissatisfied": 15.62 }, { "category": "3", "Very Satisfied": 1.56, "Satisfied": 56.25, "Dissatisfied": 32.81, "Very Dissatisfied": 9.38 }, { "category": "4", "Very Satisfied": 7.81, "Satisfied": 56.25, "Dissatisfied": 28.13, "Very Dissatisfied": 7.81 }, { "category": "5", "Very Satisfied": 7.81, "Satisfied": 35.94, "Dissatisfied": 43.75, "Very Dissatisfied": 12.5 }, { "category": "6", "Very Satisfied": 26.56, "Satisfied": 57.81, "Dissatisfied": 12.5, "Very Dissatisfied": 3.13 }, { "category": "7", "Very Satisfied": 10.94, "Satisfied": 43.75, "Dissatisfied": 28.13, "Very Dissatisfied": 17.19 }, { "category": "8", "Very Satisfied": 28.13, "Satisfied": 53.13, "Dissatisfied": 14.06, "Very Dissatisfied": 4.69 }, { "category": "9", "Very Satisfied": 26.56, "Satisfied": 64.06, "Dissatisfied": 7.81, "Very Dissatisfied": 1.56 }, { "category": "10", "Very Satisfied": 21.88, "Satisfied": 46.88, "Dissatisfied": 28.13, "Very Dissatisfied": 3.13 }, { "category": "11", "Very Satisfied": 1.56, "Satisfied": 43.75, "Dissatisfied": 45.31, "Very Dissatisfied": 9.38 }, { "category": "12", "Very Satisfied": 1.56, "Satisfied": 39.06, "Dissatisfied": 40.63, "Very Dissatisfied": 18.75 }, { "category": "13", "Very Satisfied": 3.13, "Satisfied": 43.75, "Dissatisfied": 31.25, "Very Dissatisfied": 21.87 }, { "category": "14", "Very Satisfied": 23.44, "Satisfied": 62.5, "Dissatisfied": 12.5, "Very Dissatisfied": 1.56 }, { "category": "15", "Very Satisfied": 9.38, "Satisfied": 53.12, "Dissatisfied": 35.94, "Very Dissatisfied": 1.56 } ] } ); </script> </head> <body> <div id="chartdiv" style="width: 50%; height: 400px; " ></div> </body> </html> My PHP returns the following: Which is the same result as I am currently entering manually.
  9. Thanks guys, going to do some more reading on this. Posted this thread just before leaving the office yesterday afternoon.
  10. Hi All, So phpMyAdmin can generate quite nice graphs, and I was wondering if it is possible to have these graphs pull through into a PHP page?
  11. Thanks, I managed to get it to work. I had single quotes instead of double quotes around the sources etc... To be honest I didn't know this made a difference. I also removed the .. in front of each file just for safe keeping and it seems to be working. It just appears as if not all the css and js files are loading, which I struggle to understand. Thanks for the assistance.
  12. Ok, so the directory structure i have is a follows... Just to see if maybe I am missing something. htdocs is the main directory as it is by default. Inside this directory I have three directories includes js css inside the includes directory I have my two include files (the include files contain the code as show through the "view source code"): css_includes.php js_includes.php for testing my main file (test.php) is in this directory as well, however I want it to eventually be directly in htdocs Inside the js directory I have all the js files that are being shown in the source Inside the css directory I have all the css files that are being shown in the source If I add the file location directly into my file (test.php) without using the includes it works perfectly. However i want to keep them out of the file itself so that in future I can just include all the required scripts with a single include. Hope this makes sense?
  13. This is what I see when I go to view source: <!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script src='../js/XRegExp.js' type='text/javascript'></script> <script src='../js/shCore.js' type='text/javascript'></script> <script src='../js/shLegacy.js' type='text/javascript'></script> <script src='../js/shBrushJScript.js' type='text/javascript'></script> <script src='../js/shBrushXML.js' type='text/javascript'></script> <script type='text/javascript'> SyntaxHighlighter.defaults['toolbar'] = false; SyntaxHighlighter.all(); </script> <script src='../js/jquery-1.10.2.js' type='text/javascript'></script> <script src='../js/zebra_datepicker.js' type='text/javascript'></script> <script src='../js/core.js' type='text/javascript'></script> <script src='../js/my_location.js' type='text/javascript'></script> <link type='text/css' rel='css/stylesheet' href='css/reset.css'><link type='text/css' rel='css/stylesheet' href='css/metallic.css'><link type='text/css' rel='css/stylesheet' href='css/style.css'><link type='text/css' rel='css/stylesheet' href='css/shCoreDefault.css'><body></body> </head> That's only the top section of the code, up until the head closing tag
  14. Ok, so what am I doing wrong? I'm sorry but you guys are being very vague
  15. No, its in my includes files. When it was in the source less the ../ it worked fine. But when I moved to an includes directory, I had to add the ../ to browse more folders down.
  16. My page is not loading any of the js / css files when trying to have them in the separate includes file. So I just get a regular html page.
  17. Hi all, I don't understand why my includes file ins't working. When I add the files inside my includes file to the page it all works as expected. I then try moving the CSS & JS files out of the main file and into and includes file that is located in my includes directory. Then it stops working. Any guidance here? Directory structure is: Main Directory = htdocs (Houses my main file) Includes Directory = includes (Houses css_includes.php & js_includes.php) JS Directory = js (Houses all the mentioned *.js files) CSS Directory = css (Houses all the mentioned *.css files) This is how I am including it in my main file: <?php include_once 'includes/css_includes.php'; include_once 'includes/js_includes.php'; ?> Inside each directory to have: css_includes.php <link type="text/css" rel="css/stylesheet" href="../css/reset.css"> <link type="text/css" rel="css/stylesheet" href="../css/metallic.css"> <link type="text/css" rel="css/stylesheet" href="../css/style.css"> <link type="text/css" rel="css/stylesheet" href="../css/shCoreDefault.css"> js_includes.php <script type="text/javascript" src="../js/XRegExp.js"></script> <script type="text/javascript" src="../js/shCore.js"></script> <script type="text/javascript" src="../js/shLegacy.js"></script> <script type="text/javascript" src="../js/shBrushJScript.js"></script> <script type="text/javascript" src="../js/shBrushXML.js"></script> <script type="text/javascript" src="../js/jquery-1.10.2.js"></script> <script type="text/javascript" src="../js/zebra_datepicker.js"></script> <script type="text/javascript" src="../js/core.js"></script> When adding these to the main file I just remove the " ../ " in front of each of the src / href and it works perfectly.
  18. That comment is not in my actual code. I just added it in for the sake of the forum post.
  19. Can I simply replace the GET with post? I tried replacing $_GET['shift'] with $_POST['shift'], but no success.
  20. Hi All, I've been working on this page for quite some time now and I have gotten it to almost work exactly as needed. The error I was getting was Line 85 in the code was $result = $query -> fetchAll (PDO::FETCH_ASSOC); I think the reason for the error was because I had multiple queries firing off at the same time when the page loaded and there fore there was no initial selection made in the drop-down menu. To see the page working I forced the URL to a selection eg original URL = page1.php, forced URL page1.php?shift=7. This made the page display and work as desired. Selecting the drop-down menu would change the check boxes as desired. However, I need to get around the error mention, and so changed the code to have a default value. The problem now however is that my drop-down menu no longer causes the check boxes to populate. Not errors are being returned either. Pleae see my code below. <?php include_once 'includes/db_connect.php'; include_once 'includes/functions.php'; include_once 'includes/session_management.php'; include_once 'includes/formatting.php'; include_once 'includes/panel.php'; include_once '/nav/menu.html'; // Page1.php // This page will simply go to the database and give us a list of agents along with their associated IDs // The user will tick checkboxes for each agent they wish to enter the status of //FUNCTION TO CREATE HTML FOR OPTIONS LIST function createOptions($optionList, $selectedValue) { $options = ''; foreach ($optionList as $option) { $selected = ($option['value']==$selectedValue) ? ' selected="selected"' : ''; $options .= "<option value='{$option['value']}'{$selected}>{$option['label']}</option>\n"; } return $options; } function db_result_to_array($result) { for ($count=0; $row = $result->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array; } ?> <script language="javascript"> function getSelectValue(selectID) { var optionObj = document.getElementById(selectID); return optionObj.options[optionObj.selectedIndex].value; } function reload(form) { //Adding the unselected options should work fine var locationURL = 'page1.php'; locationURL += '?shift=' + getSelectValue('shift'); //Perform the reload self.location = locationURL; } </script> <?php if ( isset ( $_GET['shift'] ) && is_numeric ( $_GET['shift'] ) ){ // There's a shift=xxx in the querystring so we use that as the select's default value $default_value = $_GET['shift']; } else { // There's no shift=xxx in the query string so a default value is assigned here like so $default_value = 7; } $shift = isset($default_value) ? intval($default_value) : false; //DETERMINE SELECTED OPTIONS PASSED ON QUERY STRING // CREATE THE DROP-DOWN MENU FROM THE SELECTED DATE $sql_1 = " SELECT DISTINCT(shift) as value , title as label FROM schedule WHERE DATE(start) = '2014-05-07' //THIS DATE IS ONLY FOR TESTING AND title NOT LIKE '%1st%' AND title NOT LIKE '%2nd%' AND title NOT LIKE '%Lunch%' AND agent_id NOT LIKE '0' ORDER BY title ASC"; $optionList = $db->query($sql_1); $shift_options = createOptions($optionList, $shift); // CREATE THE SQL TO GRAB ALL USERS FROM THE DB & EXECUTE QUERY - ADDED $SHIFT VARIABLE WHICH IS CREATED BY THE OPTIONS MENU $sql = " SELECT DISTINCT(agent) , agent_id FROM schedule WHERE DATE(start) = '2014-05-07' AND shift = $shift ORDER BY agent ASC"; $query = $db -> query ($sql); $result = $query -> fetchAll (PDO::FETCH_ASSOC); // $result should now hold an array of agents. Here, a check is done to make sure and die if not if ( count ($result) == 0 ) die ("No agents found"); // At this point, there's at least 1 record in the $result array and we can loop through without an error // STARTING THE HTML PAGE echo "<body>"; echo "<div id='container'>"; echo "<div id='content' style='margin-top:-45px;'>"; echo "<img src='images/logo.png' alt=''></img>"; echo "<h1>Auxilium</h1>"; echo "<div id='stylized' class='form'>"; // Start the HTML form echo "<form name='page1_form' action='page2.php' method='post'>"; echo "<h1>Shift Roster</h1>"; echo "<input type='hidden' name='username' id='username' value='$username' readonly style='background-color: #C9C9C9'>"; echo "</div>"; echo "<div id='shift' class='form3'>"; echo "<table border='0' class='shift'><tbody>"; echo "<tr>"; echo "<td>"; echo "<label>Shift :"; echo "<span class='small'>Shift to update / edit</span>"; echo "</label>"; echo "</td>"; echo "<td>"; echo "<select name='shift' id='shift' onChange='reload(this.form)'>"; echo "<option value='99'>--- Select a Shift ---</option>"; echo $shift_options; echo "</select>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='2'>"; echo "<p class='shift_highlight'>Select the agents whom's attendance status you wish to update by checking the tick boxes below."; echo "</td>"; echo "</tr>"; // Loop through all the Agents returned from the query above so that the user can select which one(s) they // want to enter the status data for foreach ( $result as $agent_info ) { // We now have an array called $agent_info which holds two keys: // agent_id // agent_name echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='agent[]' value='" . $agent_info['agent_id'] . "' id='" . $agent_info['agent_id'] . "'>"; echo " "; echo "</td>"; echo "<td>"; echo "<for='" . $agent_info['agent_id'] . "'>"; echo "<span class='buttonlabel'>"; echo $agent_info['agent']; echo "</span>"; echo "<br>"; echo "</td>"; echo "</tr>"; } echo "<tr>"; echo "<td colspan='1'>"; echo "<br>"; // Give the user a submit button echo "<input type='submit' name='submit' value='Submit'>"; echo "</td>"; echo "</tr>"; // Close the HTML form echo "</form>"; Any help will be appreciated here.
  21. I understand what you are suggesting and will make the changes as suggested. What I normally do is use the functions in the actual form before moving it to my functions.php file. This I will still do once everything is working. Sorry I forgot to include the error messages, these are the messages that I get: Notice: Trying to get property of non-object in C:\autopage_auxilium\htdocs\shift_form_schedule3.php on line 141 Fatal error: Call to a member function fetch_assoc() on a non-object in C:\autopage_auxilium\htdocs\shift_form_schedule3.php on line 156 I still have a long way to go with what I am learning on my coding. So I do apologize for my disorganized code. Thanks
  22. Hi All, So I finally got my code to work, loading the different users as per the drop-down selection with my 4 radio buttons next to each user. The challenge I'm now having with my form however is that initially there is an error when my form is opened. This is because there are no values selected in the second query. Basically what I want to know, is how to a prevent the error from displaying? Below is the code I am using: <?php include_once 'includes/functions.php'; include_once 'includes/register.inc.php'; include_once 'includes/session_management.php'; include_once 'includes/formatting.php'; include_once 'includes/db_connect.php'; // INCLUDING THE TOP LOGIN / LOGOUT PANEL include 'includes/panel.php'; // INCLUDING THE NAVIGATION MENU include '/nav/menu.html'; ?> <?php //FUNCTION TO CREATE HTML FOR OPTIONS LIST function createOptions($optionList, $selectedValue) { $options = ''; foreach ($optionList as $option) { $selected = ($option['value']==$selectedValue) ? ' selected="selected"' : ''; $options .= "<option value='{$option['value']}'{$selected}>{$option['label']}</option>\n"; } return $options; } //DETERMINE SELECTED OPTIONS PASSED ON QUERY STRING $shift = isset($_GET['shift']) ? intval($_GET['shift']) : false; //$agent = isset($_GET['agent']) ? intval($_GET['agent']) : false; //$tertiary_category = isset($_GET['tertiary_category']) ? intval($_GET['tertiary_category']) : false; //GENERATE OPTIONS FOR THE SHIFT OPTIONS $query = "SELECT DISTINCT id AS value, shift AS label FROM shift_structure WHERE active_status = 1 ORDER BY id"; $optionList = $db->query($query); $shift_options = createOptions($optionList, $shift); //SELECTING THE AGENTS THAT ARE SCHEDULE FOR THE MENTIONED SHIFT if($shift) { $query = "SELECT shift AS value, agent AS label FROM schedule WHERE id = $shift"; $optionList = $db->query($query); $agent_options = createOptions($optionList, $shift); } ?> <html> <head> <title>Agent Analysis</title> <script language="javascript"> function getSelectValue(selectID) { var optionObj = document.getElementById(selectID); return optionObj.options[optionObj.selectedIndex].value; } function reload(form) { //Adding the unselected options should work fine var locationURL = 'shift_form_schedule3.php'; locationURL += '?shift=' + getSelectValue('shift'); // locationURL += '&secondary_category=' + getSelectValue('secondary_category'); // locationURL += '&tertiary_category=' + getSelectValue('tertiary_category'); //Perform the reload self.location = locationURL; } </script> </title> </head> <body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin:0;padding:0" bgcolor="#B0E0E6"> <div id="container"> <div id="content" style="margin-top:-45px;"> <img src="images/logo.png" alt="none"></img> <h1>Auxilium</h1> <!-- <h2>Sliding login panel with jQuery - Demo</h2> --> <div id="stylized" class="form"> <form id="form" name="form" method="post" action="process/submit_agent_analysis.php"> <h1>Agent Analysis</h1> <label>User Logged In : <span class="small">You are logged in as</span> </label> <input type="text" name="username" id="username" value="<?php echo htmlentities($_SESSION['username']);?>" readonly style="background-color: #C9C9C9"> <!-- DISPLAY THE DETAILS OF THE LOGGED IN USER <label>Form Reference Number : <span class="small">Number Reference to link queries</span> </label>--> <input type="hidden" name="voc_reference" id="voc_reference" value="<?php echo $random;?>" readonly style="background-color: #C9C9C9"> <label>Shift : <span class="small">Shift that is being updated</span> </label> <select name='shift' id='shift' onChange="reload(this.form)"> <option value=''>--- Select a Shift ---</option> <?php echo $shift_options; ?> </select> <?php $query = " SELECT DISTINCT(agent) , agent_id FROM schedule WHERE shift = $shift AND DATE(start) = curdate() "; $result = $db->query($query); $num_results = $result->num_rows; function db_result_to_array($result){ //--------------------------------------------------------------------- for ($count=0; $row = $result->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array; } //--------------------------------------------------------------------- $irow=0; while($row = $result->fetch_assoc()) { if($row['agent']==1) $checked=" checked='checked'"; else $checked=''; if($row['agent']==1) $checked2=" checked='checked'"; else $checked2=''; if($row['agent']==1) $checked3=" checked='checked'"; else $checked3=''; if($row['agent']==1) $checked4=" checked='checked'"; else $checked4=''; echo "<table><tr>"; echo "<td><label>".$row['agent'].":"; echo "<span class='small'>Agent's attendance status</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='1'".$checked."/>" ; echo "<span class='radiobutton'>Present</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='2'".$checked2."/>" ; echo "<span class='radiobutton'>Late</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='3'".$checked3."/>" ; echo "<span class='radiobutton'>Absent</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='4'".$checked4."/>" ; echo "<span class='radiobutton'>AWOL</span>"; echo "</label></td>"; echo "</tr>"; $irow++; } echo "</tr></table>"; var_dump($_POST); ?> </form> </body> </html>
  23. Hi All, I closed an earlier thread I had as I have made a number of changes, and did some research to try and achieve what I am looking for. I have managed to get a few bit and pieces of code together, that I would like to try and combine to get the desired result. What I want to achieve on my form is the following: A user selects a "shift" from a drop-down that is created from my MySQL database. This list is created using the following: function createOptions($optionList, $selectedValue) { $options = ''; foreach ($optionList as $option) { $selected = ($option['value']==$selectedValue) ? ' selected="selected"' : ''; $options .= "<option value='{$option['value']}'{$selected}>{$option['label']}</option>\n"; } return $options; } //DETERMINE SELECTED OPTIONS PASSED ON QUERY STRING $shift = isset($_GET['shift']) ? intval($_GET['shift']) : false; //$agent = isset($_GET['agent']) ? intval($_GET['agent']) : false; //$tertiary_category = isset($_GET['tertiary_category']) ? intval($_GET['tertiary_category']) : false; //GENERATE OPTIONS FOR THE SHIFT OPTIONS $query = "SELECT DISTINCT id AS value, shift AS label FROM shift_structure WHERE active_status = 1 ORDER BY id"; $optionList = $dbo->query($query); $shift_options = createOptions($optionList, $shift); This script reloads my form: <script language="javascript"> function getSelectValue(selectID) { var optionObj = document.getElementById(selectID); return optionObj.options[optionObj.selectedIndex].value; } function reload(form) { //Adding the unselected options should work fine var locationURL = 'shift_form_schedule.php'; locationURL += '?shift=' + getSelectValue('shift'); // locationURL += '&secondary_category=' + getSelectValue('secondary_category'); // locationURL += '&tertiary_category=' + getSelectValue('tertiary_category'); //Perform the reload self.location = locationURL; } </script> On selecting the shift, I need to create: 1. A list of agents 2. A series of 3 radio buttons for each agent The values of the radio buttons will need to be the agents name. Then on submitting the form each agent's selected radio button needs to be populated into the relevant column in a table. The table has 5 columns Date - This is the date of the shift Shift - The actual shift Present - Radio Button 1 Late - Radio Button 2 Absent - Radio Button 3 The radio button columns need to be populated with the agents name, depending on which button was selected in the form. This is a bit of code that I found that will create my radio buttons, however, I do not know how to: 1. Include it into my form. 2. Exclude the database connection section of the code as I already have this in my includes at the top of the form. 3. Adjsut the code to create 3 radio buttons per agent, currently is only creates 1 radio button for each agent. And I can only select one button at a time. I need to be allowed to select 1 button per agent. <?php require_once 'includes/myradio.php'; define('HOST', 'localhost'); define('USER', 'username'); define('PASS', 'password'); define('DBNAME', 'database'); $db = new mysqli(HOST, USER, PASS, DBNAME); if ($db->connect_errno) { echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error; } else { $sql = "SELECT shift, title as name FROM schedule"; $result_db = $db->query($sql); if (!$result_db) { echo $db->error . ' Error perform query!'; } else { $aa_student = array(); while ($row = $result_db->fetch_object()) { $aa_student[$row->shift] = $row->name; } myradio($aa_student, 10, 'STUDENT_RADIO', 0, 2); } } $db->close(); Here is the functions for creating the radio buttons: <?php function myradio($array, $checked, $name, $return=0, $option=1) { if (count($array) <= 0) { return; } $str_radio = ""; if ($option == 1) { for ($i = 0; $i < count($array); $i++) { if ($array[$i] == $checked) { $str_radio .= "<input type=\"radio\" name=\"{$name}\" value=\"{$array[$i]}\" id=\"id{$array[$i]}\" checked=\"checked\"/>"; $str_radio .= "<label for=\"id{$array[$i]}\">$array[$i]</label>"; } else { $str_radio .= "<input type=\"radio\" name=\"{$name}\" value=\"{$array[$i]}\" id=\"id{$array[$i]}\"/>"; $str_radio .= "<label for=\"id{$array[$i]}\">$array[$i]</label>"; } } } if ($option == 2) { foreach ($array as $value => $label) { if ($value == $checked) { $str_radio .= "<input type=\"radio\" name=\"{$name}\" value=\"{$value}\" id=\"id{$value}\" checked=\"checked\"/>"; $str_radio .= "<label for=\"id{$value}\">{$label}</label>"; } else { $str_radio .= "<input type=\"radio\" name=\"{$name}\" value=\"{$value}\" id=\"id{$value}\"/>"; $str_radio .= "<label for=\"id{$value}\">{$label}</label>"; } } } if ($return) { return $str_radio; } else { echo $str_radio; } } ?> Please let me know if you require any additional information.
  24. Ok, so I've done some work on this and tried applying the logic you had helped me with in an earlier thread. I'm almost certain that I'm not doing this right though. <?php //FUNCTION TO CREATE HTML FOR OPTIONS LIST function createOptions($optionList, $selectedValue) { $options = ''; foreach ($optionList as $option) { $selected = ($option['value']==$selectedValue) ? ' selected="selected"' : ''; $options .= "<option value='{$option['value']}'{$selected}>{$option['label']}</option>\n"; } return $options; } //DETERMINE SELECTED OPTIONS PASSED ON QUERY STRING $shift = isset($_GET['shift']) ? intval($_GET['shift']) : false; $agent = isset($_GET['agent']) ? intval($_GET['agent']) : false; //$tertiary_category = isset($_GET['tertiary_category']) ? intval($_GET['tertiary_category']) : false; //GENERATE OPTIONS FOR THE SHIFT OPTIONS $query = "SELECT DISTINCT id AS value, shift AS label FROM shift_structure WHERE active_status = 1 ORDER BY id"; $optionList = $dbo->query($query); $shift_options = createOptions($optionList, $shift); //SELECTING THE AGENTS THAT ARE SCHEDULE FOR THE MENTIONED SHIFT if($shift) { $query = "SELECT shift AS value, agent AS label FROM schedule WHERE id = $shift ORDER BY agent"; $optionList = $dbo->query($query); $agent_options = createOptions($optionList, $agent); } ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Shift Report - Agent Analysis</title> <script language="javascript"> function getSelectValue(selectID) { var optionObj = document.getElementById(selectID); return optionObj.options[optionObj.selectedIndex].value; } function reload(form) { //Adding the unselected options should work fine var locationURL = 'shift_form_schedule.php'; locationURL += '?shift=' + getSelectValue('shift'); // locationURL += '&secondary_category=' + getSelectValue('secondary_category'); // locationURL += '&tertiary_category=' + getSelectValue('tertiary_category'); //Perform the reload self.location = locationURL; } </script> <!-- INCLUDING THE NAVIGATION MENU --> <?php // INCLUDING THE TOP LOGIN / LOGOUT PANEL include 'includes/panel.php'; // INCLUDING THE NAVIGATION MENU include '/nav/menu.html'; ?> <div id="container"> <div id="content" style="margin-top:-45px;"> <img src="images/logo.png" alt="Altech Autopage"></img> <h1>Auxilium</h1> <!-- <h2>Sliding login panel with jQuery - Demo</h2> --> <div id="stylized" class="form"> <form id="form" name="form" method="post" action="process/submit_voc.php"> <h1>VOC Root Cause Analysis</h1> <!--<p>This is the basic form layout. We can edit it as required.</p>--> <!-- DISPLAY THE DETAILS OF THE LOGGED IN USER --> <label>User Logged In : <span class="small">You are logged in as</span> </label> <input type="text" name="username" id="username" value="<?php echo htmlentities($_SESSION['username']);?>" readonly style="background-color: #C9C9C9"> <!-- DISPLAY THE DETAILS OF THE LOGGED IN USER <label>Form Reference Number : <span class="small">Number Reference to link queries</span> </label>--> <input type="hidden" name="voc_reference" id="voc_reference" value="<?php echo $random;?>" readonly style="background-color: #C9C9C9"> <label>Shift : <span class="small">Shift that is being updated</span> </label> <select name='shift' id='shift' onChange="reload(this.form)"> <option value=''>--- Select a Shift ---</option> <?php echo $shift_options; ?> </select> <label><?php print $agent;?> : <span class="small">Agent being updated</span> </label> <input type ='radio' name='present' value="<?php echo $agent;?>"> <?php print $agent;?>
×
×
  • 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.