Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. see below - it also hides error messages and helpful messages your application might be outputting.
  2. i recommend that you read the documentation - http://us3.php.net/manual/en/language.oop5.basic.php the very first sentence describes the syntax for a class definition.
  3. table is a reserved mysql keyword. if you really have a database table named table, rename it to something else.
  4. the name of your class in that file is not db. you named your class new.
  5. based on your reply - $policytypeid = substr($policytypeid, -1);
  6. there's nothing obviously wrong with your code (outside of using a mysql function instead of your database class to escape string data), provided your class is defined in db.php and the include statement for that file is working. what have you done to troubleshoot the problem to narrow down the possibilities?
  7. the code referencing the $_POST variables needs to be all after the if(isset($_POST['submitbtn'])){ line. there's several possible problems for the code not working - 1) your form doesn't contain username/email fields with those exact names (spelling or capitalization) or the form is otherwise broken and could only be setting $_POST['submitbtn']. 2) your queries could be failing, in which case the num_rows values will be zero or perhaps null, i don't recall, both of those would be considered not equal to 1. one possible reason for the queries to fail is if the username/email contains sql special characters that are breaking the sql syntax (because the insert apparently is working, this is not the case, but you should ALWAYS escape string data being put into a query to prevent sql injection and errors OR use prepared queries.) 3) due to prior testing, you could have more than one row in your database table with the same username/email you are entering and num_rows is returning a value > 1, which of course is not equal to 1. some suggestions to address these - 1) your code MUST validate user supplied input. if your code already had validation logic and it was telling you the username or the email is empty, that would help you troubleshoot where the problem is occurring at. 2) you MUST always test if queries are working or not before attempting to use the result form the queries. if your error checking logic says the query ran without any errors, you will know the num_rows value is valid and can be used. 3) your database table definition should enforce uniqueness. this will prevent duplicate values. also, you should use positive, fool-proof logic. there are several values that are not equal to 1 (-1, 0, 2, ...). your code should use a comparison that will only be true for the desired value(s.) in this case the num_rows values should be == (equal to) zero.
  8. it kind of depends on if there are or can be other values accross in any set and if there are or can be other values down with 5,...10... or higher? and do you need to validate that the values being tested are only in those sets of values or is just getting the number from the end enough?
  9. i don't see where you are setting the $email or $username variables, so are they empty, which would insure that your queries don't match any rows?
  10. my last attempt to get you to find the cause of the problem and stop wasting time with javascript as a fix (it's been a week+ since your first thread about logging out when a form is submitted.) based on actual information you have finally shown and that you are just now attempting to tell the server side code which submit button has been used (or more likely which form out of multiple forms has been submitted), i can state with 98% certainty what is wrong with your side code that is causing the problem. you have three things to fix that is causing the logout - 1) your form(s)/submit button(s) are not uniquely identified and/or your current server-side code isn't using anything to control which of the form processing logic is executed. it's likely that any form submission at all, is running your login form processing code and since at that time there isn't any username/password, the login fails and actually logs the current user out. 2) your form processing code isn't validating the submitted data, so an empty username/passowrd causes the login to fail, when in fact you should never try to log someone in if they left the username/password empty. 3) your login form and login form processing code should not be active at all if the current user is already logged in. and here's why this javascript you are trying to add won't fix the problem. let us say that you do manage to get the form submit buttons to be disabled for an amount of time. what will happen when they become enabled and someone submits a form? exactly that same thing that is currently happening. your current form processing logic will run all/or at least for the login logic, there will be no username/password submitted in this case, the login logic will fail to find a matching user and log the current user out.
  11. you have a $ in front of your id column name in your query, you are also missing the $ in front of the $id variable name in your query OR you could remove the single-quotes from around the id column name in your query. if you include a debugging step where you echo out your sql query statement, you would have likely seen this problem.
  12. if there is a problem with the session.save_path setting/folder, the php error_reporting/display_errors settings should report things like permission problems, non-existent folder...
  13. example (untested) showing some of the suggestions - <?php require ('../edb.php'); if (!$con) { die("MySQL could not connect!"); } // any input filtering validation would go here... // get data for Adviser drop-down $result= mysql_query("SELECT id, LastName, FirstName, UserType FROM `eusers` WHERE UserType='ADV' or UserType='STF' ORDER by LastName ASC"); $adviser_data = array(); while ($row = mysql_fetch_assoc($result)){ $adviser_data[] = $row; } // get data for main content (if current can have more values then y or n, this query needs a where clause added back in to just return y or n values) $data=mysql_query("SELECT * FROM `adocs_fsg_profile` INNER JOIN `eusers` ON eusers.id = adocs_fsg_profile.AdviserCode ORDER BY LastName ASC, FirstName ASC, DocName ASC, DateUploaded DESC"); $main_data['y'] = array(); $main_data['n'] = array(); while($row = mysql_fetch_assoc($data)){ $main_data[strtolower($row['current'])][] = $row; // this will make arrays of arrays with y or n as the main index } // end of the business logic // you could close the database connection here or let php close it when the script ends // the logic and mark-up needed to produce the page follows - // template/function to produce the output for the main content on this page function main_output($title, $data){ ?><p class="Text_SubHeading"><?php echo $title; ?> </p> <table width="650" border="0" align="center" cellpadding="4" cellspacing="0"> <tr class="text-sectionheading"> <td width="100">Date </td> <td width="150">Adviser</td> <td width="200">Document</td> <td width="100">Version</td> <td width="50">Current</td> <td width="50">View</td> </tr> <?php foreach($data as $test) { $id = $test['id']; echo"<tr>"; echo"<td class='text-questions'>".$test['DateUploaded']."</td>"; echo"<td class='text-questions'>".$test['LastName'].", ".$test['FirstName']."</td>"; echo"<td class='text-questions'>".$test['DocName']."</td>"; echo"<td class='text-questions'>".$test['Version']."</td>"; echo"<td class='text-questions'>".$test['Current']."</td>"; echo"<td><a class='".$test['cssclass']."'href =".$test['URL'].">".$test['ImageType']."</a>"; echo "</tr>"; } ?> </table> <?php } // the html document - ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>your title</title> </head> <body> <table width="680" border="0" align="center" cellpadding="4" cellspacing="0"> <tr> <td> </td> </tr> <tr><td class="text-heading"><p>Financial Services Guides and Adviser Profiles</p><p class="Text_Heading_Black1">PAGE STILL IN DEVELOPMENT</p> <form id="form1" name="form1" method="get" action=""> <span class="text-questions">Adviser: </span> <select name="advselect" id="advselect"> <option value=" " selected="selected"> </option> <?php foreach($adviser_data as $row){ // if you need to dynamically select an option based on an existing choice, you would have logic here to do so echo '<option value="'. $row['id'] .'">'. $row['LastName'] .', '. $row['FirstName'] .'</option>'; } ?> </select> <input type="submit" name="advselect" id="advselect" value="Filter / View" /> </form></td> </tr> <tr><td> <?php main_output('Current Version',$main_data['y']); // you might want to add some logic so that if there is no corresponding data, you don't display an empty table, but display a meaningful message main_output('Previous Versions',$main_data['n']); ?> </td> </tr> </table> </body> </html>
  14. i have some suggestions concerning your code - 1) you need to separate your 'business logic' (the php logic that is determining what to do on the page and producing the content that will be displayed) from your 'presentation logic' (minimal php code and the html/javascript/css making up the output you are sending to the browser.) basically, a majority of the php code will be first on the page, following at the end by essentially a html template that is just echoing php variables or at most looping over arrays of data producing the html output from that data. this business logic would be where you test for and validate the filter values that are received by the page, that are then used to determine what to query for. 2) you need to make one database connection. you are currently including/requiring the connection code multiple times and since you are testing if the connection worked in you main code, i can only assume you are not selecting a database, resulting in queries that are failing with errors. you are also closing the connection at several points. this opening/closing of the database connection takes a significant amount of time, to the point that you will probably notice a difference in the page generation time if you just open one connection at the start and close that one connection at the end (or just let php close it automatically when the script ends.) 3) you need to ALWAYS have error checking logic for your sql queries. the suggestion in a previous thread was not just for debugging when things don't work. when a query error does occur, you need to display that when developing code and log it when on a live server. 4) your filtering determines that the page will display. your html forms should use method='get' as you are determining what will be gotten and output on the page. this will also simplify the logic of persisting those filters between page requests as they will already be present in the url/$_GET array. 5) lastly, the mysql (no i on the end) functions are depreciated. all new code needs to be written using the mysqli or pdo database libraries so that you don't need to rewrite your code in the near future. edit: 6) i just noticed you are referencing both a $con and a $conn database connection variable.
  15. if your last post means you have closed the browser and the session is not present when you open the browser again, that is the normal operation of sessions (by default, a session lasts for just the current browser session.) if you mean that, with the browser continuously open, you cannot refresh adminnotes.php or navigate to any other page and then back again without loosing the session, that's not normal and something is still going on with your session id cookie/session data on the server. here's one possibility, if the sessions sometimes last and sometimes don't, based on your session.save_path setting, assuming you are on a shared web server (there could be dozens of other accounts using that same /tmp folder.) all the other accounts could be deleting the session data files due to the session garbage collection they are triggering. if you are on a shared web server, you need to create your own folder for the session data files and set your session.save_path setting to point to that folder. beyond that, this appears to be a problem with the session id cookie and that the browser is not sending it back to the web server with the page requests because the browser doesn't think the cookie matches the sub-domain/host-name and/or path of the url being requested. when you look at the session id cookie in your browser, does the host: parameter match exactly the url you are browsing to or does it have a different sub-domain/host-name, i.e. www. or no www from the url you are browsing to? does the host: parameter in the browser start with a dot (.), which causes it to match all variations of the domain name or is it just the domain.com, without the leading dot. also, are you using an actual domain name that you own, or are you using a temporary url based on your web host's main domain name, i.e. some_temporary_name.your_web_host's_domain.com?
  16. when you look at the cookie's parameters in your browser, it should show path: /
  17. if this is the master php.ini, you will need to restart your web server to get the change to take effect. if this is a local php.ini (in your document root folder) the change should have taken effect on the next page request. also, since you currently have a cookie with a setting in it that doesn't work, you should delete that cookie and/or completely close your browser.
  18. set it to - output_buffering=off you will need to restart your web server to get the change to take effect.
  19. i'll assume you are getting your "Something went Wrong" message? you are not escaping your string data before putting it into the query statement, so all the characters like - ', ", \t, \r, \n that are in the data are breaking the sql syntax. you need to use mysql_real_escape_string() on all string data being put into a query statement that can contain any characters that have meaning in the sql query or you need to use prepared query statements. you also need to switch to the mysqli or pdo database library functions. the msyql functions are depreciated in php5.5 and you don't want to have to rewrite your code later when the mysql functions are removed.
  20. the session.cookie_path should be just / the current setting will only cause the session id cookie to match urls like - your_domain.com/tmp
  21. your current symptom is that of the browser not sending the session id cookie back with each request it makes to the server. two possibilities - 1) your browser is configured to not accept cookies (the session id cookie) and even though you see the cookie in your browser, the browser isn't sending it back to the server. 2) the session id cookie's domain or path is set to something that doesn't match the url or path for the page(s) and the browser isn't sending it back to the server due to the mis-match. given that the session auto start was set, does your php.ini also have any other session._______ values set in it, particularly the session.cookie_domain and session.cookie_path settings?
  22. is your php installation with the mysqli extension working now or are you still getting a fatal error at the mysqli functions? if mysqli is working, what is your current code?
  23. ummm. the reason your code is no longer logging you out is because your server side code is no longer being executed and whatever it is doing to cause the logout is no longer being triggered. the if($_SERVER['REQUEST_METHOD'] == "POST"){ ... }, assuming your form is using method='post', would have detected the form submission (you can also put a hidden field into the form that you can detect.) at this point, without seeing your form and form processing code that reproduces the problem, no one can help you.
  24. one of the points of setting php's error_reporting/display_errors was to see if there were any errors with the session_start() statement. you need to set error_reporting/display_errors before the session_start() statement and it needs to be on both pages, because it can be one, the other, or both pages with a problem.
  25. the code you have posted doesn't contain any code that is responsible for the title/price/description data, so it will be really hard to help you with what is wrong with your code. first, you need to define what your intent is. an INSERT query inserts a new row, an UPDATE query allows you to change values in an existing row. what are you trying to do?
×
×
  • 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.