Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. I have no idea what initGateway() is supposed to do or how you expect that to work when redirecting to the href URL. This really isn't a PHP issue. Get it to work how you want by hard-coding it. Then figure out how to write them dynamically using PHP. I think you are just wanting a download link that doesn't open a new page? If so, there are plenty of resources out there. Just do a search for "PHP force download"
  2. I think it would make more sense to LIMIT the query based upon the number of files in the directory. You then know you would never have more DB results than files. Then only loop through the DB results. If you have more files than DB results, then those remaining files would not get renamed. Also, I would use glob() to get the files. Here's my approach whic I think is simpler $dir = 'home/test/'; $date = '2012-07-26'; $files = glob($dir.'*') //Get the contents of directory $files = array_filter($files, 'is_file'); //Remove directories from array $fileCount = count($files); //Set count of files //Run query to get records up to the number of files $query = "SELECT number FROM test WHERE date = '{$date}' GROUP BY number ORDER BY date, time LIMIT {$fileCount}"; $result = mysql_query($query); while($oldName=array_shift($files) && $row=mysql_fetch_assoc($result)) { //Create new file name $newName = "{$dir}{$row['number']}.jpg"; rename($oldName, $newName); }
  3. What you are asking doesn't make sense. PHP executes server-side and JavaScript executes client-side. There is no way to make them both "activate" at the same time. But, let's break down what those are doing to see how they might fit together. - The PHP code is simply dynamically creating the href value for the link dynamically. - The JavaScript onClick event is calling a function and then returning false. That means if there was an href property assigned it would not run. So, if we put those together only the JavaScript event would fire. Unless the user has JS disabled then only the href would be called. If you want both actions to work you would do a return true, or remove the return completely. Then when the user clicks the link the JS event will first run, then the browser will be redirected to the href. I personally hate writing a lot of code on one line where it makes it hard to read, so I would create the href value separately - then create the actual link. Give this a try: $file_url = urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')); $href_url = "{$_SERVER['PHP_SELF']}?mp3={$file_url}"; echo "<a href='{$href_url}' onClick='initGateway(); return true;'>Download your MP3 file.</a>";
  4. The problem also exists in FF. But first, one suggestions. I see you are passing a value that is the same as the field name to the function. Instead of passing the value with each call to setCategory(), just pass a reference to the object. <input type="radio" name="category" value="muscleTestingGrades" id="muscleTestingGradesRadio" onclick="setCategory(this);"> Then in the function setCategory you can reference the value using .name of the referenced object. function setCategory(obj) { category = obj.name; That should cut down on a lot of repetitive, hard-coded values. Now, as to your problem the branch of logic for the 'muscleTestingGrades' value you have this for(i = 0; i < abbreviationsMuscleTestingGrades; i++) The problem is that abbreviationsMuscleTestingGrades is not a number. I think you are looking for the length property for(i = 0; i < abbreviationsMuscleTestingGrades.length; i++) However, there seems to be some other problems as well. I think the script is getting put in an infinite loop or something.
  5. Sure, you could store a session value each time that page is loaded. But, I'm not really understanding what you are REALLY trying to achieve. I think the issue you are having is that when loading contactus.php you don't know if the error was a previous error or a new error. If that is the case, then check for the error as you do now - then remove the error. if ($_SESSION['captchaError']==true) { echo "<p id='contErrorMsg' style='display: none;color:red;'>Please fill the required fields</p>"; $_SESSION['captchaError'] = false; }
  6. There are several solutions. 1. Use str_replace() to remove the after extracting the line you need Does every line with '^' have an ' ' at the end? If so, 2. If you don't expect the ampersand to be included in the data you can change the regex to \^([^&]*)\ 3. If the ampersand can be in the data you need then you can use this regex \^([.*) \ - may need to escape some of those characters
  7. Right, the page is not displayed until processing completed and you are redirecting the user to a different page before processing completes. But, since you are already storing the captcha error in session data you can simply use that on the contactus.php page to display the error.
  8. Here is a very rudimentary example //Create function to output one DIV of content for a record function displayContent($value, $class) { echo "<div class='{$class}'>{$value}</div>\n"; } //Loop through records to be displayed foreach($arrayOfData as $recordID => $value) { if(isset($prevValue)) { //Create output for previous value/record //Using selected class/style displayContent($prevValue, 'alignRight'); } $prevValue = $value; } //Create output for very last record using a different class displayContent($lastValue, 'alignLeft');
  9. Yes. Were you wanting more help? Posting some code might help us to do that.
  10. As jotorres1 was alluding to, you will want to create these select lists dynamically. You should have the values/text for the options stored in a database, array or something similar on the server-side. Then you can create a function/process to create the select lists AND auto-select a value based upon a preset. Here is an example: <?php function createSelectList($options, $selectedValue=false) { $output = ''; foreach($options as $value => $text) { $selected = ($value === $selectedValue) ? ' selected="selected"' : ''; $output .= "<option value=\"{$text}\"{$selected}>{$text}</option>\n" } return $output; } //Create arrays of all select lists/values. This can be retrieved from //database or with hard-coded arrays. If stored in arrays, put them in //a separate file and include them when needed $statuses = array( '0' => 'Single', '1' => 'Married', '2' => 'Seperated', '3' => 'Divorced', '4' => 'Widowed', '5' => 'Tell You Later', ); //Call function with the list of values to create the options $statusOptions = createSelectList($statuses, $selectedValueFromDB); //Then output the options in the HTML ?> <div id="profile_info"> <form> <div id="profile_info_item"> <label> <select name="r_status" id="r_status"> <?php echo $statusOptions; ?> </select> </label> </div>
  11. The only way to do what you are asking would be to save a value each time you execute the script. But, you really have not provided enough information to really provide a full answer. Are the "visits" by the same user? Is the iteration through server supposed to be over the course of a session (if so use a session variable) or across sessions (use a cookie). Or are the "bisits" supposed to be based upon all users as they access the page(s)? If so, you would need to store a value server-side.
  12. Well, I would start by looking at all that nested functionality. I try to avoid that as it gets hard to understand where each if/while/etc section of code is ending. Also, if you have a large block of code executing with a loop or if, you can always break that out into a separate method. It looks like that, aside from the 'despatchDate' method you simply created a long procedural block of code in the 'checkCustomer' method. It also looks like you may be storing serialized arrays in the database. That is typically a bad practice. And here is something that caught my eye. Look at these two small chunks of code if(!isset($option[0]) || $option[0] == 24) { $extraDays = 0; } else $extraDays = $option[0]; $optionDays += $extraDays; if(!isset($base[0]) || $base[0] == 24) { $baseDays = 0; } else $baseDays = $base[0]; These are essentially doing the exact same thing. You could just create a method to do that logic. private function addDays($days = 0) { return ($days!=24) ? $days : 0 ; } Then where you had those two blocks of code previously you could just do this: $optionDays += $this->addDays($option[0]); $baseDays = $this->addDays($base[0]); That's just an off the cuff suggestion, but I'd need to better understand the intent to really provide a 'valid' solution.
  13. In my opinion, keeping the data "pure" is keeping it EXACTLY as entered. For example, I see some people using htmlentities() on data before storing it in the database. But, htmlentities() is designed to safeguard data being displayed in an HTML page. If the data needed to be output into a text file or some other format it could be made unreadable because of the translation of the data. So, I would always advise not excluding data unless there is a need to. Only escape/cleanse the data as needed based upon the specific output/usage. Different "languages" don't have any particular issues with specific data that I am aware of - it is HOW the data is used. You can always make a determination when the other processes/languages are implemented to determine what procedures are needed to safeguard against possible data issues. Besides, the hyphen or apostrophe could *potentially* cause issues within some processes, but it wouldn't make sense to exclude those for a name field. Again, my opinion, is to only reject content when there is a legitimate business need (e.g. no letters in a phone number). Then escape/sanitize the data as appropriate based upon the usage/output. The only time I would strip out content without the user's knowledge would be something like a phone number. I would strip out the formatting characters (periods, spaces, parents, etc.) and store only the digits of the phone number. That way I could display the phone number in a consistent format during output.
  14. Is there a business reason you are stripping out anything that is not in that character class list of characters? Because there is no technical/security reason to do so. What about someone with a hyphenated name "Smith-Johnson"? I'm not advocating that you add the hyphen to that character class. What I am saying is that for you to try and determine what all the "valid" characters are (especially for a name) is presumptuous. either you are going to have instances where you are going to piss someone off because you are telling them their name is not valid or you are going to leave the opportunity to submit characters that *could* be a problem if not already handled appropriately. So, the solution is to simply escape/sanitize all data as appropriate for how it will be used. When using in a query use the appropriate function/process for the database. When echoing to an html page use something like htmlentities(), etc. Now, if you have a business reason to exclude certain characters then by all means exclude them. But, you should not strip them out. Because then you would be saving data that is different than the user entered. Just as above, you might think there is no valid reason for a user to use tags in their name, but how do you know someone didn't legally change their name to something stupid such as "<b>John</b>" (with the bold tags). So, instead of stripping it out, do a test. if the input fails the test give the user an appropriate error message and make them fix it. And don't forget about accented characters!(e.g. ?, ?, ?, ?, ?)? Because those aren't covered in your RegEx expression either.
  15. You should be using the Database specific escaping function instead of creating your own escaping. In this case mysql_real_escape_string(). Then use that on all data used in queries that could contain problematic data. Here is a better solution for the first process $height = (int)$_POST['height']; $feet = floor($height / 12); $inch = $height % 12; $heightSQL = mysql_real_escape_string("{$feet}' {$inch}\""); //Note: still need to escape the double quote because //the string is defined in double quotes Now, as for putting the same value into another table, if you want to extract the value first and then insert it again you would want to use mysql_real_escape_string() again. But, that's not necessary. There shouldn't be a need to insert the same value into different tables if the table structure is set up appropriately. And, if you really need to insert the value again, just do it directly in a query instead of extracting the value into PHP. Note that the double quote still needed to be escaped because it is defined inside a double-quote. Bu
  16. To add a little more clarity. Use array_intersect() to find the duplicates. Then use array_diff() on those dupes and array2 to get array2 without the dupes. A long hand example: $dupes = array_intersect($array1, $array2); $array2 = array_diff($array2, $dupes); A single line example: $array2 = array_diff($array2, array_intersect($array1, $array2)); Or, create a function passing array2 by reference: //Remove duplicate values from 2nd array function removeDupes($arr1, &$arr2) { $dupes = array_intersect($arr1, $arr2); $arr2 = array_diff($arr2, $dupes); } //Usage removeDupes($array1, $array2); //After calling the function $array2 will be reset without the dupes
  17. Maybe I'm missing something, but based what I see the query would be as simple as this. SELECT * FROM item_price WHERE Dayset >= (SELECT Dayset FROM item_price WHERE Totrain > 20 LIMIT 1) ORDER BY Dayset LIMIT 3
  18. Why dump the results into an array only to use the array for output. Just create the output from the query results. $query = "SELECT component_name, image_filepath, component_category FROM tbl_components ORDER BY component_category"; $result = mysql_query($query); $category = false; while($row = mysql_fetch_assoc($result)) { if($category != $row['component_category']) { $category = $row['component_category']; echo "<br>{$category}<br>\n"; } echo "{$row['component_name']} <img src='{$row['image_filepath']}'><br>\n"; }
  19. $query = "SELECT component_name, image_filepath, component_category FROM tbl_components"; $result = mysql_query($query); $categorized_items = array(); while($row = mysql_fetch_assoc($result)) { $category = array_pop($row); $categorized_items[$category][] = $row; }
  20. No, regex would be a waste. But, that function is pretty much useless since you can just as easily use (int) $var instead of calling the function. You've basically created a function that does something that already exists.
  21. instead of Yes, but that structure is poor form. Using that type of logic could cause problems later on.
  22. Give this a try $max_columns = 5; $col_width = 140; $table_width = $col_width * $max_columns; //Open table echo "<table width='{$table_width}'>\n"; //Create header row echo "<th>\n"; for($col=0; $col<$max_columns; $col++) { echo "<td width='{$col_width}'></td>\n"; } echo "<th>\n"; //Process query results $recCnt = 0; while($row = mysql_fetch_assoc($result)) { $recCnt++; //Open new row if needed if($max_columns%$recCnt == 1) { echo "<tr>\n"; } $price = (int) $row['item_price']; $sale = ($row['item_sale']) ? 'YES' : 'NO'; $item_id_url = urlencode($row['item_id']); echo "<td align='center'>\n"; echo "<img src='{$png}' id='resizeMe' /><br>\n"; echo "<span class='admin_list'><u>{$row['item_code']}</u></span><br>\n"; echo "P <b>{$price}</b><br>\n"; echo "Stocks: <b>{$row['item_stock']}</b><br>\n"; echo "Sale? <b>{$sale}</b><br>\n"; echo "<span class='admin_list_date'>Date Added: <b>{$row['time_reg']}</b></span><br>\n"; echo "<a href='edit_item.php?id={$item_id_url}'>[edit]</a> \n"; echo "<a href='delete_item.php?id={$item_id_url}' onclick='return confirm('Are you sure you delete item {$row['item_id']}?');'> [delete]</a> \n"; echo "<a target='_blank' href='edit_item.php?id={$item_id_url}'>[view]</a>\n"; echo "</td>\n"; //Close row if needed if($max_columns%$recCnt == 0) { echo "</tr>\n"; } } //Close last row if needed if($max_columns%$recCnt == 0) { echo "</tr>\n"; } //Close table echo "</table>\n"
  23. Stopped working how? What errors are you getting and/or what is happening and what do you expect to happen differently? You say it stopped working which implies it was working before. What did you change? I see you are checking for error conditions for connecting to and selecting the database. But, you don't seem to be displaying the actual error in either of those two cases. That's fine for a production environment, but when developing you need that information to understand what the problem is. Try this $link = mysqli_connect('217.174.', 'xymalf' , 'po'); if (!$link) { die("Unable to connect: " .mysql_error()); //debugging line $output = 'unable to connect to database server.'; include 'output.html.php'; exit(); } if (!mysqli_select_db($link, 'xymalfco1')) { die("Unable to select db: " .mysql_error()); //debugging line $output = 'unable to locate db'; include 'output.html.php'; exit(); }
  24. He meant use one of the database DATE types: date, datetime, timestamp, time, & year. If you use something other than a MySQL date/time format for date/time values you are preventing the ability to use many of the built-in functions for dealing with date/time value. You only need to store a date once. You can then output that date in any way you need to using either the MySQL or PHP functions as needed. If you ONLY need the date (and not the time component), then you should use the 'date' type. You would store the value in the format YYYY-MM-DD. Then when you retrieve the value, just use the PHP date() function to output it in whatever format you wish.
  25. A few things: 1. You do not have any error handling on your query. It would have told you the query was empty. 2. Create your queries as string variables. Then if there is an error you can echo the query to the page to inspect it for errors. 3. If you are only using the 'title' from the table, then don't use '*' in your select query. It is a waste of resources. 4. Why are you using stripslashes() on a value extracted from the database? Always understand what 'format' the values shoud be in and what processes should be used to escape the values based upon the usage.
×
×
  • 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.