Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. i recommend that you echo the $query value so that you can see if it is what you expect. also, why are you putting external data values into the sql query statement, then preparing the query? you use a prepared query by putting place-holders into the sql query statement where the data values are at, then you bind the actual data to the place-holders.
  2. there's a set of user written functions that provide the same functionallity as the php5.5 password hash functions - https://github.com/ircmaxell/password_compat
  3. it's likely (pun intended) that you cannot like things until you are a full member (which i believe currently starts at 10 posts.)
  4. multiple posts can be made in the same second you are running a query to retrieve posts. by using the timestamp, you can miss new posts, that then show up in the next update as read, but where never shown as unread/new. you need to use the auto-increment id of the highest record that was displayed in the last update to find 'new' posts in the next update. see this reply for more info - http://forums.phpfreaks.com/topic/292925-if-mysql-table-updated-since-page-load/?hl=%2Bsmf&do=findComment&comment=1498777
  5. the issue is in the php code, not the mysql database. stick to the thread in the php coding forum section.
  6. programming help doesn't mean free programming services. if you cannot attempt to do the work needed to create, change, or fix your code, you need to hire someone to do it for you.
  7. programming help forums are not here to find or give you things you want. see the forum's pinned/sticky post - http://forums.phpfreaks.com/topic/195880-this-board-is-not-a-script-repository/
  8. if your select/option menu(s), inside the subdomains() function, are supposed to be dependent on the value that is submitted from the domain select/option menu, the current code is missing how browsers and web servers (http requests and responses) work. when your page gets requested by the browser, the domain select/option menu is output to the browser. the next step would be for the visitor to select one of the options and submit the form. this will cause the page to be requested again with $_POST['domain'] containing the value of the option that was selected. it's then up to the code to detect that a form was submitted and take the $_POST['domain'] value and use it the way it wants. you need a specific section of form processing code, and any form porcessing code should be near the start of your file and be before you output any of the html on the page (i.e. before the <!DOCTYPE html> tag.) lastly, if this code is just determining what to display on the page, your form(s) should use method='get', not post.
  9. it would help if showed exactly what you got as output in your browser, but i'll take a guess it looked like this - if so, either you don't have php installed (or it's not working) on your web server, or you used a file extension other than .php, or you opened the file directly in your browser or editor. you need to browse to the url of the file, on a web server that has php installed. if you have a localhost development system installed, the url would be similar to - http://localhost/your_file.php
  10. the database class you found is more of the nonsense code that gets published on the web. it contains no initialization logic, so using it for more than one query in a row will mix property values together, which is probably what's causing the current error (the bind_param() parameter type string contains the type values from the previous query and the current query.) i recommend you write your own code, so that you learn and gain in your own experience, rather than to try and use bits of code posted on the web.
  11. the code you are asking about is just forming the list of column names and VALUES place-holders for the insert query - INSERT INTO table_name (list of column names here...) VALUES (list of prepared query place-holders here...) that loop, and the two lines before it initializing the two variables, can simply be replaced with these two lines of code, which might make it clearer what it is doing - $columns = implode(', ',array_keys($data)); $holders = ':'.implode(', :',array_keys($data));
  12. topic locked. when the OP completely rewrote/changed the architecture in the jan 2014 post, he should have started a new thread and the coding was substantially changed again in mar 2014, resulting in a completely different test site, which again should have been a new thread. if the OP returns to this thread (he's not been active here since mar 2014), please start a new thread with your current version and current url, along with a current .txt file at that url with a link in it to your phpfreaks profile.
  13. in addition to needing PDO's exception mode turned on (see reply #6 in this thread) for your try/catch to do anything, are you sure that the code where your query is at is even being ran? are you getting the "Added Issue<br /> $sqlIssue<br />" output? and on the chance that your code is doing a header() redirect with output_buffing turned on, so that you wouldn't see any output from your code, what exact end result in the browser are you seeing when you run your code?
  14. your program logic, literally, is not correct, in this - $_SESSION['uname']=$s1||$b1; that is setting the session variable to the logical (boolean) result of the value in $s1 OR'ed with the value in $b1. this will be either a true or false value, depending on what values are in the two variables. your registration processing and your login processing are two separate events. each one should be complete and distinct. if you want to automatically log the member in when registration is complete, just set the session variable in the registration code (note: you can set the username in a session variable, for display purposes, assuming you won't ever allow users to change their username, but you should set a session variable with the user_id, the auto-increment id from the user table for that user.) you also need exit; statements after your header() redirect statements to prevent the rest of the code on your page from running while the browser is requesting the page given in the redirect statement. lastly, forget about using php include statements to virtually copy/paste together your application. what you have shown is a wall of repetitive logic, form processing logic that's being ran unconditionally (which would be throwing a bunch of php errors), and logic that's trying to display query errors simply because no form was submitted. start with the simplest code that's need, until you gain experience that would let you write and troubleshoot more advanced code.
  15. when your ajax request is made, the only thing that the code on the page should send back to the browser is the expected data. that means no <!DOCTYPE tag and none of the markup that makes up the main page. in order to do this all on one page, you must use conditional statements and other flow control statements (exit; for example) to insure that only the correct portions of the code run when the page is originally requested and when the ajax request is made. once you get your code organized correctly, you need to actually debug what it is doing to find out where it is working and where it is not to pin down where the problem is at.
  16. after you made the database connection, did you enable exceptions for that connection? if not, the default is PDO::ERRMODE_SILENT and exceptions won't be thrown.
  17. based on this direct access check - if(__FILE__ == $_SERVER['SCRIPT_FILENAME']) exit('Restricted!');, the code you are showing us is in an included file. return'ing from an included file returns to the main program that included the code and the main code still continues to run, and who knows what it is doing, redirecting/including... you need to use an actual exit; statement to insure that code stops running. it's also possible that something your login.php page is doing is causing the problem. this code is include/redirect happy, making it hard, without having all the code, to determine everything it is actually doing. some general debugging tips - i would put the ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); as the first thing after your first opening <?php tag in your main code (or ever better, as settings in your php.ini) so that any errors in the include/session_start/header() redirect will also be reported. make sure that output_buffering is set to false in your php.ini and that you are not using any output buffing in your code. having buffering on hides both php error messages and output that your code sends and will also allow header()/session_start() statements to work in instances where the code on your page is laid out incorrectly.
  18. the only thing in the posted code that could cause an 'unexpected' occurrence of your code to be ran is this - if(!isset($_SESSION['Username'])){ header("Location: login.php"); } since you don't have an exit;/die; statement after the header() redirect, when you are not logged in and visit that page, the rest of the code you have shown still runs, which would cause an insert query to be run. then if you then login and repeating the process, a second insert query would run. i also hope you plan on validating the $_GET['app'] value before blindly putting it into an include statement, as an un-validated input will allow directory traversal and let anyone include anything they want, which would typically be used for privilege elevation (a regular user can cause the code to include administrative level files.)
  19. then that narrows down the problem to something on the server-side. does the code where your insert query is at only exist once on the page? is it actually being included, and could be included/required twice? is the code where your insert query at, actually inside the datatable_insert_function() function being called by the switch/case statement or is it inline with all the main code and that's actually the same page as your main code, so that it gets requested once when you browse to the page and a second time by the ajax request?
  20. your browser is probably requesting the php page twice, though there are server-side reasons pages can get requested/run twice. have you checked your web server access log to look at the requests being made to see if there are two requests together?
  21. this sounds like a bad database table design. correctly designed database tables have one row for each distinct data item, making it easy to insert, retrieve, update, delete, or associate each data item to related data in other tables. post an example of your data is to get the best help.
  22. nope. your description of what the problem is, isn't clear. is the problem when you are trying to edit/update an existing record or when you are trying to create/insert a new record? does your form even have a way of entering the data for a new record? just posting the code snippets of three functions doesn't tell us what your main code is, how it is using those functions, or how it is using the submitted data from the form. btw - your functions are poorly written. they look like you took your main code and wrapped function definitions around parts of it. you should not be making/closing a database connection inside each function that needs to use the database. your main code should be making the database connection, which you pass as a call time parameter into any function that needs it. and because your base_connectDatabase() function isn't returning any sort of connection variable, your functions that actually use that connection are probably using the global keyword to access the database connection. your functions should each only do what their name implies - the drop down function should only generate the drop down (the multi-select javascript in that function shouldn't be part of that function and it should be written using a class selector, not an id selector, so that you can use it for multiple drop downs on the page.) you should not be redirecting in the add/edit functions. it's your main code that should control what happens on the page.
  23. because this a 'how to get started' thread, rather than a thread with any actual php code in it, moving topic to the misc forum section...
  24. the php json code is sending the 'correct' => $totalCorrect;response back to the browser, that the ajax code is using to display how many answers are correct via this - $('#results').text(response.correct) the most immediate problem why your code isn't working is because your form field name = '...' attributes are question-1, question-2, question-3, ... you would need to use those same names in the $_POST[...] variables to access the values. another problem is because you are submitting the ajax request to the (apparently) same page as your main page, all the output, including the form's html, is being sent back to the browser in the ajax response. you would need to have conditional logic so that when it receives the post request, that the only output it sends is the json_encode() output.
  25. you know the total number of rows in $total_records. you can simply limit the $to value to that. $to = min($total_records,$to); // use the smaller value in $total_records or in $to. as to how to limit the number of pagination links that are displayed around the currently selected page, see the phpfreaks,com main site pagination tutorial - http://www.phpfreaks.com/tutorial/basic-pagination specifically, see the $range variable and how it is used.
×
×
  • 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.