Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. I'll assume that means that you also found and fixed what ever was causing the query to fail in the first place...
  2. You have some error checking logic in your code to test if some of the queries execute with or without an error, but you are not preventing the remainder of the relevant code from running when there is a query error, so you get follow-on errors. You need to troubleshoot why the query is failing (your echo "Hata: ". mysql_error(); statement would be outputting a mysql error message) and you need to add an else{} condition to your error checking logic to prevent the code from using the non-existent result from a query when the query fails edit: or use return false; in the error checking logic so that the code returns from the function call and does not continue running past that point.
  3. For your existing code, you would NEVER select all the rows from a database table and scan through them using relatively slow parsed/tokenized/interpreted php code to find if a value exists. You would use a WHERE clause in the query to directly find any row(s) that match the desired value. Also, the foreach(){} loop you have makes no sense. Even if you were selecting more than one column, the value you are trying to find is in one specific column. You would not loop over all the columns trying to find it. You would test the one specific column the value is in. Since you are selecting only one column in the query, the foreach loop is looping over one thing and is a waste of typing to have it in the code. Lastly, since the posted code is attempting to find one (or no) specific email address in the table (with a WHERE clause in the query), you would not use a while(){} loop anyway. To address finding if an entered email address exists in the table - <?php if(isset($_POST['pass-reset'])){ // find if the entered email exists $query = sprintf("SELECT * FROM users WHERE email = '%s'", mysql_real_escape_string(trim($_POST['email']))); $result = mysql_query($query) or die("Query failed: $query<br />Error: " . mysql_error()); if(mysql_num_rows($result) > 0){ // a matching row was found, fetch and use the data here... echo "Email found."; $row = mysql_fetch_assoc($result); } else { // no matching row, handle that condition here... echo "Email not found."; } }
  4. The extra !== false comparison is unnecessary. The while() statement already tests if the condition is true/false.
  5. This topic has been moved to PHP Regex. http://forums.phpfreaks.com/index.php?topic=364705.0
  6. The payment gateway forms that have and use the price submitted from the form are only useful for 'donations', where the visitor is the one who selected the amount in the first place. For anything else, you need to set the price for each item within the payment gateway's control panel.
  7. The global keyword is only used inside of function definitions (and even then it should not be used.) Everywhere else, it doesn't have any effect at all (except to take up processing time.)
  8. A) The code you posted is missing the most important part that would be needed to help you, the checkSession() function definition. B) The code is using the @ error suppressor. This will only hider troubleshooting (if your mysql_select_db statement is failing, you would want to know that since that would indicate a fundamental problem with your database.) You should never put @'s in your code to hide errors. You need to find and fix the cause of all errors. C) The code has a long list of variables being brought into the printHeader function using the global keyword, one of which is a duplicate of the call-time parameter being passed into that function. Using the global keyword makes it harder to write and troubleshoot code without having/knowing what ALL the code is. Where are those variables being set, which ones are being modified inside of that function, are they supposed to be modified inside of that function, or are they even used inside of that function? D) The code is over 10 years out of date, having nothing to do with php4 vs php5. It's using session_register that was depreciated (in favor of using $_SESSION variables) and disabled by default about 7 years before the end of life of php4. Instead of session_register/session_is_registered, you need to set and reference $_SESSION[...] variables and you need a session_start() statement (before you output anything to the browser) on any page that sets or references a $_SESSION variable. E) Both the session_name and the ini_set('session.gc_maxlifetime',3600) statements must go before any other session related statements. Based on the out of context code fragment you posted, the following is likely (would require knowing exactly what all your code and data is doing) the equivalent code rewritten to final php4 and current php5 standards - <?php session_name("adminSession"); // must go before the session_start ini_set('session.gc_maxlifetime',3600); // must go before the session_start session_start(); // uses the above two settings // based on the session_register('adminLoggedIn') statement, there would be a session variable - $_SESSION['adminLoggedIn'] that indicates if the current visitor is logged in as an admin // this is used in the form page? $_SESSION['mandatoryMessage'] = "<font class='normalText'>[All entries marked with <font class='errorText'>*</font> are mandatory]<br><br></font>"; // I did not do anything with the remaining variables identified in the session_register() statements since is not clear from the posted code if/what the values are being used for. $dbConnect = mysql_pconnect("<snip>", "<snip>", "<snip>"); // persistent connections only work on a very few server/php combinations. Most likely you are getting a normal connection from this. mysql_select_db("dbtvm1", $dbConnect); $curDateQuery = mysql_query("SELECT DATE_FORMAT(CURDATE(), '%M %d, %Y'), CURDATE()"); // if you have more than one mysql connection, you need to use the $dbConnect variable as the 2nd parameter in your mysql_query statements list($curSysDateDisp,$curSysDateValue) = mysql_fetch_row($curDateQuery); // shorter version of the code you had function printHeader($LoggedIn) { // when you call this function, it should be printerHeader($_SESSION['adminLoggedIn']); if(!checkSession($LoggedIn)) { header("Location: ../index.php"); exit; } echo $LoggedIn; ?>
  9. <form action="test.php" method="post"> <p> <label for="fontSize">Taille :</label> <select id="fontSize" name="fontSize"> <?php $post_size = intval(isset($_POST['fontSize'])? $_POST['fontSize'] : 25); $size_list = array( 20 => 'tiny', 25 => 'small', 30 => 'medium', 40 => 'large' ); // output the selected/default option - echo "<option value='$post_size' selected='selected'>{$size_list[$post_size]}</option>"; foreach($size_list as $size => $name){ // output the remainider of the non-selected options - if($post_size !=$size){ echo "<option value='$size'>$name</option>"; } }
  10. All it would take to NOT display the already selected/first entry inside the loop is an if(){} statement to skip outputting the <option> for that entry.
  11. This topic has been moved to PHP Applications. http://forums.phpfreaks.com/index.php?topic=364677.0
  12. The name of your <select is 'state', not 'sta'
  13. a) The question has nothing to do with sessions and the data is obviously being serialized when it is stored, since it is being unserialized to get to the point of displaying the data/property values, b) The thread is 3 years old and the OP has been active since then, so it's unlikely he is still looking for an answer to this, c) The solution would be to either ignore the error or include likely class definitions until the error is eliminated, d) Locking thread so that no one else spends time replying in it.
  14. There's absolutely no reason to break the data into individual scaler variables and if you did, you would use extract with one of the optional parameters to prevent overwriting existing variables. I have a football form that can submit 2500+ pieces of team/roster update data. I don't have one individual scaler $variable created from that data, let alone 2500 of them. Everything is handled and processed as arrays for the sets of related data. If you want a list (array) of expected form field names for validation/data access purposes, then do that (loop over the array of expected field names and access that field name in the $_POST array.) But you don't need to have individually named variables for each piece of data.
  15. You should NOT be making a series of named variable for a set of data. Having variables named like - $bob, $jim, ..., doesn't indicate the meaning of the data and it indicates that you either have some hard-coded logic later that references those variables (meaning that you must edit your code every time you change the amount of data) or that you will attempt to loop over that series of variables using the same method that you used to create them. You must also insure that the list of variables are not used anywhere else in your code so that you don't get unexplained results by overwriting variables. You should be using an array for a set of same meaning data, where the array name indicates the purpose of the data, not whom the data belongs to - $ages['bob'] = 44; $ages['jim'] = 33; Also, variable variables are 3x slower than using an array, which would have an impact if you have a large set of data. Edit: using an array will also simplify and speed up the code - $ages = array_combine($namesArray , $agesArray);
  16. Your code isn't checking if the file was successfully uploaded before attempting to use the uploaded file information. Testing the ['type'] element will fail if the file didn't upload successfully. You need to test if a form was even submitted and you must test if the $_FILES array is not empty (exceeding the post_max_size setting will cause the $_FILES array to be empty) and that the ['error'] element is a zero (UPLOAD_ERR_OK) - <?php // upload form handling if($_SERVER['REQUEST_METHOD'] == 'POST'){ // the request_method is tested since some of the possible errors leave the $_POST and $_FILES arrays empty // a post form was submitted, check if a file was successfully uploaded if(!empty($_FILES) && $_FILES['Image']['error'] == UPLOAD_ERR_OK){ // a file was successfully uploaded. // you can reference the ['name'],['type'],['size'], and ['tmp_name'] elements // validate and process the uploaded file information here... } else { // the upload failed, due to one of the following reasons - // uploads are not enabled on the server // the form is invalid - doesn't have the proper enctype or doesn't have a type='file' field // the size of the post data exceeded the post_max_size setting // a php detectable upload error occurred - http://php.net/manual/en/features.file-upload.errors.php echo "Upload Failed!"; } }
  17. If you want a general solution that doesn't have the problem that started this thread, you need to give up on the notion of copy/pasting together a web page using php include statements. Programming does not involve magic or the ability to go back in time.
  18. See the recommend method of building a page at this link - http://forums.phpfreaks.com/index.php?topic=364499.msg1726616#msg1726616
  19. Your page is probably being requested twice, either by the browser (different browser do this for different reasons), by something you are doing in your code, by url rewriting, or even how your web host is sending http requests to your web server (assuming this is occurring on a live web site.) Check your web server's access log to see if there are closely spaced http requests from the same ip address with the same id on the end of the url. If you are getting multiple requests and they are not due to a coding error on your part, the ultimate solution is to NOT maintain a simple count, but to store a record in a database table that records, at a minimum, the article id, the ip address of the http request, and the datatime of the http request. You will then be able to use this information to filter out and ignore duplicate http requests to get a more accurate count. Another method to detect and prevent duplicate requests is to set session variables with the article id and the datatime of the http request and if another request occurs for the same article id within a short time (~ 1 second), ignore it.
  20. The array will let you access information by positionid - $before[2] will be an array of arrays of all the RBs, where the index of the subarray is the playerid and the subarray data is that player's record ($row.) You can either access a specific player - $before[2][some_playerid] (will be the $row data) or by element - $before[2][some_playerid]['firstname' ] or you could iterate over all the RB's - foreach($before[2] as $playerid => $row){ } You can also iterate over all the positionids, then all the playerids under each postionid - foreach($before as $positionid => $arr){ foreach($arr as $playerid=>$row){ } }
  21. Do you have php's error_reporting set to E_ALL and display_errors set to ON, because when I run the code you just posted (with a } added to close the else { statement), on a table I have with positionid and playerid, I get a $before array that looks like - Array ( [17] => Array ( [1] => Array ( [id] => 1 [playerid] => 1 [teamid] => 1 [positionid] => 17 [jersey_no] => 2 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) [2] => Array ( [id] => 2 [playerid] => 2 [teamid] => 1 [positionid] => 17 [jersey_no] => 4 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) [3] => Array ( [id] => 3 [playerid] => 3 [teamid] => 1 [positionid] => 17 [jersey_no] => 14 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) <snip there are many players with position id 17> [18] => Array ( [5] => Array ( [id] => 5 [playerid] => 5 [teamid] => 1 [positionid] => 18 [jersey_no] => 31 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) [6] => Array ( [id] => 3043 [playerid] => 6 [teamid] => 1 [positionid] => 18 [jersey_no] => 38 [start_date] => 2012-08-28 [end_date] => 9999-12-31 ) [7] => Array ( [id] => 7 [playerid] => 7 [teamid] => 1 [positionid] => 18 [jersey_no] => 45 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) [8] => Array ( [id] => 8 [playerid] => 8 [teamid] => 1 [positionid] => 18 [jersey_no] => 33 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) [9] => Array ( [id] => 9 [playerid] => 9 [teamid] => 1 [positionid] => 18 [jersey_no] => 46 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) <snip> ... [5] => Array ( [1434] => Array ( [id] => 1434 [playerid] => 1434 [teamid] => 16 [positionid] => 5 [jersey_no] => 77 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) [2179] => Array ( [id] => 2960 [playerid] => 2179 [teamid] => 29 [positionid] => 5 [jersey_no] => -- [start_date] => 2012-08-19 [end_date] => 2012-08-28 ) [2735] => Array ( [id] => 2735 [playerid] => 2735 [teamid] => 30 [positionid] => 5 [jersey_no] => 71 [start_date] => 2012-08-10 [end_date] => 9999-12-31 ) [3015] => Array ( [id] => 3040 [playerid] => 3015 [teamid] => 29 [positionid] => 5 [jersey_no] => 70 [start_date] => 2012-08-24 [end_date] => 9999-12-31 ) ) ) The only changes I made to your code is my table name is player_details and I didn't use an explicit $connection variable in the mysql_query() statement.
  22. Your print_r output of the $row array doesn't contain a 'playerid' field, so there no way that using $row['playerid'] as an array index would result in anything other than the symptom you have described, only the last set of values being present in the resulting array. Also, you are using code like - if ($row['positionid'] =="2") ... $startingRBsbefore[]. That implies you have a bunch of logic, duplicated for each possible positionid value. You should instead have ONE array, i.e. $before or similarly named, and if you need to group the data by positionid, use that as an array index - $before[$row['positionid']][] = $row; // this will make a primary array with all the 2's (RB), 3's, 4's grouped together. The key for each $row sub-array will just increment, starting at zero. If you want/need to access the data by both positionid and the playerid, you would use - $before[$row['positionid']][$row['playerid']] = $row; // this will make a primary array as above, with the key for each $row sub-array being the playerid.
  23. The $_SERVER['REMOTE_ADDR'] comes from the TCP/IP data packets.
  24. EVERYTHING that is not inside of <?php ?> tags is treated as literal 'in-line' html on the page and is output to the browser as is, even the blank lines. Just one blank line or one character that is outside of <?php ?> tags will prevent headers from working. In your last code, lines 2,3,4,6,7,8,10,12,14,15,16, and 17 are all in-line html that is being output to the browser.
  25. I recommend that you go and change your password ASAP. A number of the views of this thread are bot scripts and search engine spiders that read and cache the content and it's only a matter of time before someone logs into your mail account.
×
×
  • 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.