Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Then you should have the 3-e's in your code - error checking (check if something worked or failed), error reporting/logging (output a user message and log all the pertinent information about the error), and error recovery (take a predictable execution path when an error occurs to prevent follow-on errors) logic in your code, If you are writing a script that you plan on releasing or the installation script for it, your code should be bullet-proof/fool-proof. If you already had error checking, error reporting/logging, and error recovery logic in your code, your code would have told you who was executing your script when it failed, what about it failed, when it failed, and where in your files/code it failed, so that you can find and fix why it failed. Using the 3-e's not only helps you debug your code, but it also helps after the fact to find and fix things like legitimate visitors doing something your logic didn't take into account or hackers trying (succeeding) to break into your script. Even if you found a method that will execute multiple queries at one time, you would never do that in a real script, since that prevents you from using the 3-e's to find exactly what didn't work when your code runs. You would execute each query separately and only move onto the next query if the previous step worked.
  2. Script requests go in the Miscellaneous forum section, where this thread was moved to from its original location. The Php coding help section is for actual problems and errors with php code you have written.
  3. I added some information to my post above, probably while you were replying -
  4. Sorry to pick, but programming is an exact science and we only see the information you supply in your posts. Someone asked an exact question for a reason (we get people trying to match all kinds of nonsense data and we only uncover the exact problem once we see the problematic data) -
  5. If the sample data you posted is what you expect the query to match, that date is not greater-than today, so that query should not return any rows. Edit: Also, your use of the OR keyword in the query will match everything with the MONTH(matrix.col_id_4) = '{segment_4}' value. You need to use () to force the operator precedence. Also, also, you should not have column names like col_id_4, ... Those don't indicate the meaning of the data and while they might have meaning for you today, they probably won't for the next person who needs to work on your code or to anyone here who would like to help.
  6. Further to the above reply, you only use the public, var (php4), protected, and private keywords when defining CLASS variables/properties. You don't use them for variables you use inside of a class function/method, that are local only to that function/method. Your $image=$_FILES['image']['name']; php statement isn't defining a class variable/property. It's a php assignment statement inside your img_Check() function. If you actually wanted the $image variable to be a CLASS variable/property, you would define it and reference it as follows - public $image; $this->image = $_FILES['image']['name'];
  7. Stop the Spammers!

  8. Posting the entire query that 'doesn't work' would help, along with a sample of the data you have in your matrix.col_id_3 column that you expect the query to match.
  9. The first reply told you exactly what was causing the error and how to fix it.
  10. At the time you declare the variable/property, you cannot assign it a variable value. Only fixed values, like a constant, number, string, empty array, or an array containing fixed values can be used in the declaration line. To assign a variable value, you need to assign it using php code in the constructor or in a class method. Edit: Also, you should not use the var keyword in php5. You should only use public, protected, and private. Php5 treats the var keyword as public.
  11. If you post the query(ies) you are having trouble converting yourself, someone can probably lend a hand at converting them.
  12. Someone already stated why part of your code is running -
  13. The form code you posted cannot possibly work (correctly) with the form processing code you posted. 1) The form's method is get. You cannot upload files using a get method form (just tested.) 2) The form doesn't have a submit field named exactly - 'Submit', so there's no way that the code testing if (isset($_POST['Submit'])){ is even running. 3) You have the UPDATE query outside of and after your form processing code, so it runs every time the page is requested and if (count($setArray) > 0) { is true, which it will be since $setArray is set by the GET method data you are currently receiving. A) Make your form method = 'post' and access all the values using $_POST (edit: except the $_FILES data.) B) You need a name= 'Submit' field in your form so that your if (isset($_POST['Submit'])){ statement will be true. C) You need to put ALL the form processing code inside of the if((isset($_POST['Submit'])){...} logic. Everything from the code accessing and validating the 'id', 'website', ... through to after the UPDATE query has been executed belongs inside of the {} for that if() statement.
  14. When you output content on a site, use htmlentities, with the second parameter set to ENT_QUOTES, so that any HTML/javascript in the content won't have any effect.
  15. You also created two accounts. After your username didn't work for the first account, what makes you think it would work for the second one?
  16. Unfortunately, a reinstall of the current forum software broke the display of foreign characters. See if your username corrects itself after the weekend when the forum is migrated to different forum software. If not, post a desired username you would like and someone on the staff will change your username to it.
  17. This topic has been moved to PHPFreaks.com Questions, Comments, & Suggestions. http://forums.phpfreaks.com/index.php?topic=365401.0
  18. You can turn off the behavior -
  19. I removed your post in the php coding help section, since you don't actually have any php code yet that you have a problem or error with that you need help with. What exactly about the layout of this do you need help with?
  20. Pagination involves 5 main parts - 1) A main query with a WHERE clause that matches the record set you are interested in or no WHERE clause if you are interested in all your records (a LIMIT clause is appended to this main query later to retrieve the specific records for any logical page.) Your main query would also have any JOINS, GROUP BY, ORDER BY terms, ... it needs to retrieve the data you want in the order that you want it. 2) A secondary query, with the same WHERE clause (or lack of) as the main query that gets a count of the total number of matching records you are interested in (used to calculate and limit the maximum logical page number.) 3) Get the requested logical page number (if any, if not default to page 1) and calculate the starting row number for the requested logical page. 4) Query for, retrieve, and display the matching records for the requested logical page. 5) Produce pagination links that allow any of the logical pages to be requested. In order to propagate any search term/filters,... you should pass them as GET parameters in the URL so that someone can bookmark a page and be able to return to that same page later. I recommend using http_build_query when building pagination links so that the code only modifies the part of the URL query string for pagination and leaves any other GET parameters as is. Sample code that does the above - <?php // settings used by this code - $rows_per_page = 20; // how many rows to display per logical page $pagination_name = 'pageno'; // the $_GET[xxxxx] index name to use for pagination $pagination_range = 3; // maximum number of pagination links to show either side of the currently selected page // connect to your database server and select your database here... // assuming this is being used for a search script, output a simple search form and produce a $where_clause to match the rows you are interested in $search_form = "<form method='get' action=''>Search: <input type='text' name='search'><input type='submit'></form>"; echo $search_form; // get and condition any search term $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $where_clause = ''; if($search != ''){ // form a simple LIKE '%search term%' comparison $where_clause = sprintf("WHERE your_column LIKE '%%%s%%'",mysql_real_escape_string($search)); } // define the main and count queries $main_query = "SELECT * FROM your_table $where_clause"; $count_query = "SELECT COUNT(*) FROM your_table $where_clause"; // find the total number of matching rows $result = mysql_query($count_query) or die("Query failed: $count_query<br />Error: " . mysql_error()); list($total_rows) = mysql_fetch_row($result); // calculate the total number of logical pages $total_pages = ceil($total_rows/$rows_per_page); // get and condition or set a default for the requested page $requested_page = isset($_GET[$pagination_name]) ? intval($_GET[$pagination_name]) : 1; // set max/min limits for the requested page. max first, then min so if the total is zero (no matching data), the requested page is 1 if($requested_page > $total_pages){ $requested_page = $total_pages; } if($requested_page < 1){ $requested_page = 1; } // calculate the starting row number for the requested logical page $offset = ($requested_page - 1) * $rows_per_page; // form the actual query to retrieve the matching data for the requested logical page $query = "$main_query LIMIT $offset, $rows_per_page"; // query for the actual data $result = mysql_query($query) or die("Query failed: $query<br />Error: " . mysql_error()); // get number of rows returned by the query for the logical page $num_rows = mysql_num_rows($result); if($num_rows == 0){ // query matched no rows echo "There are no matching records to display on this page."; } else { echo "Your query matched $total_rows record" .($total_rows > 1 ? 's' : '').". "; echo "Displaying records: ".($offset+1)." - " . ($offset+$num_rows) . ".<br />"; // loop over the matching rows and output the data the way you want on your page while($row = mysql_fetch_assoc($result)){ echo $row['your_column'] . '<br />'; } } // build pagination navigation links (if there's more than one page) // this code uses http_build_query to build the query string on the end of the URL so that any existing get parameters, such as a search term, are not modified. This code only modifies the pagination get parameter and leaves all other get parameters as is. $pagination_links = ''; // build pagination links in a string (output it later in your actual content on the page) if($total_pages > 1){ // produce 'first' and 'prev' links if($requested_page > 1){ // 'first' page link $_GET[$pagination_name] = 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= "<a href='?" . http_build_query($_GET, '', '&') . "'><<</a> "; // 'prev' page link $_GET[$pagination_name] = $requested_page - 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'><</a> "; } else { // text only place holders $pagination_links .= " << < "; } // loop to produce links for a range of pages around the currently selected page for($x = $requested_page - $pagination_range; $x < $requested_page + $pagination_range + 1; $x++){ // if between min and max page number if($x > 0 && $x <= $total_pages){ // if currently requested page, output text only place holder if($x == $requested_page){ $pagination_links .= " [<b>$x</b>] "; } else { // output page link $_GET[$pagination_name] = $x; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'>$x</a> "; } } } // produce 'next' and 'last' links if($requested_page != $total_pages){ // 'next' page link $_GET[$pagination_name] = $requested_page + 1; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'>></a> "; // 'last' page link $_GET[$pagination_name] = $total_pages; // set/replace the pagination GET parameter (all other GET parameters unchanged) $pagination_links .= " <a href='?" . http_build_query($_GET, '', '&') . "'>>></a>"; } else { // text only place holders $pagination_links .= " > >>"; } } // output the pagination navigation links echo $pagination_links; // echo the links wherever you want in the content on your page
  21. You would need to post your test code for the first two cases. Using a custom error handler won't work at all for parse errors in your main file because your main code never runs to call the set_error_handler() when there is a parse error in your main file. It should work for parse errors in included/required files, after the point where you call set_error_handler().
  22. Your code works for warnings and notices. What makes you think it does not?
  23. I wish you would post the complete and actual mysql error you got. What looks like the start of the sql statement to you, might give us a clue as to what is causing the error.
  24. I would do something like this - <?php $file_name = 'test.csv'; // name of csv file $lines = file($file_name,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // read all the lines into an array // callback function to filter csv lines using an index (the column in the csv line, starting at 0) and a min and max value function _filter_csv(&$item, $key, $arg){ $values = array_map('trim',explode(',',$item)); // explode and trim values if($values[$arg['index']]>=$arg['min'] && $values[$arg['index']]<=$arg['max']){ // test if the supplied index/column is between the min and max values inclusive return; // value in range, simply return (do nothing) } $item = ''; // value outside of range, clear value } array_walk($lines,'_filter_csv',array('index'=>2,'min'=>4,'max'=>); // keep values in the age (index = 2) column that are between the min and max values (4 and inclusive $lines = array_filter($lines); // remove empty entries echo "<pre>",print_r($lines,true); // display result for demo purposes
  25. The phpeasystep code, rewritten to do something current, useful, and secure - <?php // checklogin.php session_start(); // if already logged in, should not be on this page at all if(isset($_SESSION['myusername'])){ header("location:login_success.php"); exit; } // check if the expected form submitted to this page if(isset($_POST['Submit'])){ // settings $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // the above settings should generally be kept in a separate file and included where needed // Connect to server and select database. mysql_connect($host, $username, $password)or die("cannot connect to database server"); mysql_select_db($db_name)or die("cannot select DB"); // condition inputs $myusername=trim($_POST['myusername']); $mypassword=trim($_POST['mypassword']); // pretend you have some validation logic for the inputs here... // remove php's magic_quote escaping, if needed if(get_magic_quotes_gpc()){ $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); } // To protect MySQL injection (more detail about MySQL injection) $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql) or die("Query failed: $sql<br />Error: " . mysql_error()); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // get the row from the result set $row = mysql_fetch_assoc($result); // set session variables (myusername and user id) and redirect to file "login_success.php" // note: there's no good reason to store the password in a session variable $_SESSION["myusername"] = $row['username']; // used for display purposes $_SESSION["user_id"] = $row['id']; // used for identification purposes header("location:login_success.php"); exit; } else { echo "Wrong Username or Password"; // a real script would have the form submit to the same page and then display the form again if the wrong username/password was entered } } ?> <?php // login_success.php session_start(); // check if logged in, if not go to the login form if(!isset($_SESSION['myusername'])){ header("location:main_login.php"); exit; } ?> <html> <body> Login Successful </body> </html>
×
×
  • 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.