Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. You are looking at my sig which states "In 99% of all cases I found the solution to your problem here: http://www.php.net". Which just means that most peoples solutions can be found by reading the manual. That was not a specific reply to your problem.
  2. I'm assuming the database field is set as an int type. If that's the case you only need to verify that the input is an integer - no need for mysql_real_escape_string(). And, number_format() would have no effect in the manner in which you are using it. According to the manual its oly return values are "A formatted version of number." So, it doesn't return false if the value is not a properly formatted number.
  3. A PHP page creates HTML code. So, if the two pages are different it is because the PHP page was coded such that the generated HTML is different. You need to find out where that difference is and fix it. I would start by simply viewing the source of both rendered pages and look for the differences (there are even applications that will do this for you).
  4. I think it's because I added some code to complete the row if there was not enough records to fill a row, but I forgot the ending TR tag. Change the last while loop as followsL if ($current_row_rec != $records_per_row+1) { while ($current_row_rec <= $records_per_row) { echo "<td></td>\n"; echo "<td></td>\n"; $current_row_rec++; } echo "</tr>\n"; }
  5. There is a very simple solution to this. Just use a header to redirect after you process the post data. You can have the page redirect to a confirmation screen. Or, if you have the form post to itself so the user can enter another record, have the page redirect to itself after processing. All POST data is stripped when redirected in that manner.
  6. Not tested, so there might be some errors. $records_per_row = 2; $SQLstring = "Select * from filmo WHERE id='$id'"; $result = @mysqli_query($conn, $SQLstring); if (!result) { echo "There was an error running the query<br /><br />"; echo "Query: $SQLstring<br /><br />"; echo "Error: " . @mysqli_error(); exit(); } if (mysqli_num_rows()==0) { echo "There were no results"; } else { $current_row_rec = 1; echo "<table>\n"; while ($Row = mysqli_fetch_assoc($result)) { if ($current_row_rec > $records_per_row) { echo "</tr>\n"; $current_row_rec = 1; } if ($current_row_rec == 1) { echo "<tr>\n"; } echo "<td>{$Row['img']}</td>\n"; echo "<td>{$Row['text']}</td>\n"; $current_row_rec++; } while ($current_row_rec <= $records_per_row) { echo "<td></td>\n"; echo "<td></td>\n"; $current_row_rec++; } echo "</table>\n"; }
  7. As long as the "html" file only included javascript code it is not a problem. That's why he/she should download that external file and make sure it is properly constructed.
  8. It doesn't matter what the extension is for a javascript include file. It can be 'js', 'html', 'xyz', 'php' or none at all. I have used 'asp' and 'php' when the include file needed to be dynamic. Although for just plain old consistency 'js' would be best. But, that would not explain the OPs problem. I would try accessing the include file directly (i.e. typing it into the browser) and downloading hte file to your PC. Then open it up in a text editor and confirm it is correct.
  9. It would be nice to see more of the code - especially how you are calling the function. Are you using 'checl_list' or 'check_list[]'? Because you have defined the names as array names, you can't referenence them in all the same ways. For example you CAN't use this: document.forms[0].check_list[] But you CAN use this document.forms[0]['check_list[]'] You only need ONE function, just pass a bool value for the check state. Here's a revise function and a way to properly reference the check objects <html> <head> <script type="text/javascript"> function CheckAll(chkObj, chkBool) { for (i = 0; i < chkObj.length; i++) { chkObj[i].checked = chkBool; } } </script> </head> <body> <form> <input type="checkbox" name="check_list[]" value="1">1<br /> <input type="checkbox" name="check_list[]" value="2">2<br /> <input type="checkbox" name="check_list[]" value="3">3<br /> <br /><br /> <button onclick="CheckAll(document.forms[0]['check_list[]'], true)">Check All</button> <button onclick="CheckAll(document.forms[0]['check_list[]'], false)">Check None</button> </form> </body> </html>
  10. As I said, using Javascript for this type of functionality will only prevent those users without JS enabled for using it. There are several other methods you could use. 1. Have an Add button which simply submits the page back to itself. The server-side page will count how many items were submitted and create fields for the number of items submitted (plus 1) and prepopulate all but the last set of fields with the submitted values. 2. Ask the suer up front how many items they will order and submit. Then display a page with the number of fields they requested. 3. use a standard shopping cart where the user add one item at a time.
  11. Well, first of all your button has no trigger. You need to add an onclick trigger to call the function . But for some reason the button will not work when it is within the form tags. I have no idea why - just move it out of the form tags with an onclick trigger and it should work: <form method="post" action="bestall.php"> <span id="writeroot"></span> </form> <input type="button" id="moreFields" value="Lägg till fler produkter" onclick="moreFields()" /> However, using javascript for something like this is a very bad solution in my opinion as it will prevent anyone without javascript enabled from using the site.
  12. I think you need to provide more information. Are you saying that you have server-side code that is writing that first block of code into an external file names js.html? I would agree with Kat, whay are you dynamically creating JavaScript to create variable content. Just use the server-side code to write that dynamica content directly.
  13. Correct. You will need to change the script to also accept $_GET credentials. Something along these lines: session_start(); if( !isset($_SESSION['username']) && !isset($_GET['username']) ) { echo 'No access'; exit(); } $username = (isset($_SESSION['username']))?$_SESSION['username']:$_GET['username'];
  14. Then pass that info when calling the script $url = 'http://www.server1.com/outputforserver2.php?u=userid&p=password'; $outputFromServer1 = file_get_contents($url);
  15. Hmm, you can't pass variables like that. Simply have a script on server 2 that calls a page on server 1 which outputs the variable content. Server 2 script $outputFromServer1 = file_get_contents('http://www.server1.com/outputforserver2.php'); Script on server 1 $outputForServer2 = "Hello World!"; echo $outputForServer2;
  16. LOL, the escape codes were parsed by the forum. I would have thought that would be handled - especially within code tags.
  17. Your codes are wrong. & is the ampersign : is the colon This '&#58;&#58;' will result in this: '::' I think you want this: s = s.replace(/::/g, '::');
  18. OK, I thought this was an interesting problem, so I decided to solve it another way. Here's another solution - don't know if it is more or less efficient than Sasa's function collate($arry) { if (!is_array($arry)) return false; $out = array(); $values = array_count_values($arry); ksort($values); while (count($values)) { $out = array_merge($out, array_keys($values)); foreach($values as $key => $value) $values[$key]--; $values = array_filter($values); } return $out; }
  19. EDIT: Thorpe beat me to it only because I was adding some additional clean up to the code. I also added code to trim the input value and to remove duplicate spaces in the string: function abbrName($name_str) { //Convert to array after removing leading/trailing and duplicate spaces $name_parts = explode(' ', trim(preg_replace('/ ( )*/', ' ', $name_str))); // //Iterrate through each word (except the last) and replace with the first letter for ($i=0; $i<(count($name_parts)-1); $i++) { $name_parts[$i] = substr($name_parts[$i], 0, 1); } return implode(' ', $name_parts); } $name = " John Robert David Smith "; echo abbrName($name); //Output: "J R D Smith"
  20. I would add... There might be a reason why you are contructing your array in that manner, but unless the the key of the first array value and the numeric value in the secondary array are unique values that you really need (e.g. 2 & 3 for green), I would suggest creating your array like this: $array = array( 1 => 'blue', 2 => 'red', 3 => 'green', 4 => 'red' );
  21. That's because you have a multidimensional array. Just create a custom search function since you are using a custom array function search_myarray($search_val, $input_array) { $return_val = false; foreach($input_array as $key => $sub_array) { if ($sub_array[0]==$search_val) { $return_val = $key; break; } } return $return_val; } $array = array( 0 => array('blue', 1), 1 => array('red', 2), 2 => array('green', 3), 3 => array('red', 4) ); $key = search_myarray('green', $array); echo $key; //Will echo 2
  22. Here is my email validation script. It returns true if the string is a properly formatted email, else false. It is pretty comprehensive. I have inlcluded the details of the validation below the script function validEmail(emailStr) { //Return true/false for valid/invalid email formatTest = /^[-\w+]+(\.[-\w+]+)*@[-a-z\d]{2,}(\.[-a-z\d]{2,})*\.[a-z]{2,6}$/i lengthTest = /^(.{1,64})@(.{4,255})$/ return (formatTest.test(emailStr) && lengthTest.test(emailStr)); } Validation Details: The username: Can contain the following characters: 'a-z', 'A-Z', '0-9', '_' (underscore), '-' (dash), '+' (plus sign), and '.' (period). May not begin or end with a period and they may not appear in succession (i.e. 2 or more in a row) Must be between 1 and 64 characters The domain name: Can contain the following characters: 'a-z', 'A-Z', '0-9', '-' (dash), and '.' (period). There may be subdomains, separated by a period (.), but the combined domain may not begin with a period and they not appear in succession (i.e. 2 or more in a row) The 'combined' domain name must be followed by a period and the TLD (top level domain). The TLD (Top Level Domain): Can contain the following characters: 'a-z', and 'A-Z'. The TLD must consist of 2-6 alpha characters in either upper or lower case. (6 characters are needed to support .museum).
  23. You need to RUN the query first! include 'library/config.inc.php'; mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbnamemain); $query="SELECT cabinet_id, cab_name, cab_description FROM $dbnamemain.cabinets ORDER BY cab_name ASC"; //Run the querey $result=mysql_query($query) or die (mysql_error()); //$result = mysql_fetch_array($query) while(list($cabinet_id, $cab_name, $cab_description)=mysql_fetch_array($result, MYSQL_NUM)) { foreach ($result as $row) { $cabinet=$cab_name. ": " .$cab_description; echo "<tr> <td width='200'>" .substr($cabinet,0,100). "</td> <td width='100' align='center'><a href='cab_edit.php?cab_id=$cabinet_id'>edit </a> | <a href='javascript:delArticle('$cabinet_id','$cab_name');>delete</a>,/td> </tr>"; } mysql_close($conn);
  24. First off your development environment should be totally separate from your production environment - i.e. not on the same server(s). There are many different routs to take depending on your particular application and how many people are working on it. In some instances it would be beneficial for each developer to have his own development environment so code that each person is working on does not interfere with the other's code. Each person can work on their own code against the current production code until it is ready for check-in. Of course this method requires VERY strict control of the code being checked- in/out to ensure one person does not overwrite another's code. Or, you could simply set up a spare machine to act as your development environment with each person working on the same set of code. For a dev environment it is best not to have it accessible outside your network. Also, you might benefit from having a stage environment that mimics your production environment so you can roll out a new release and ensure it is working properly before moving to production. In addition, you can have one or more test environments between development and stage. It all depends upon your needs, resources and the risk you want to take on.
  25. ??? I don't have a clue as to why that would work, but if it does, so be it. I was going to suggest creating the entire select list as a string variable within php and then include that variable in your template.
×
×
  • 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.