Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. By opening a connection in each script that needs a connection. Web servers are stateless. All the resources used on any page request are destroyed when the server finishes serving each request. Even if you were on a web server/php combination that supported persistent database connections, each of your scripts must still execute the code necessary to get one of the existing persistent connections or create a new connection if no existing connection is available.
  2. Depending on what your current code is and what you saw in front of you when you tried it, that could mean any of a dozen or so different things. What you have done to pin down what your code is doing and at what point your code and data is as expected and at what point it is not?
  3. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_month What exactly doesn't work (your code could contain dozens of errors, sight unseen and unknown to us, that could produce the symptom "it doesn't work") and what exactly did it do v.s. what you expected (for all we know you don't have any matching data)? Without your code and a statement of what you saw in front of you when you tried it on your server with your data, it is simply impossible to help you.
  4. In his post he suggested creating links that would set $_GET['month'].
  5. You should always use over-all (initial and final) double-quotes when forming a query, because A) It allows you to put single-quotes inside the query without producing php syntax errors, and B) allows you to put php variables inside the query and have them replaced with their value at runtime. Edit: And in fact, why did you switch from the double-quotes and forming the query in a variable that you used in the first post in this thread?
  6. Use a HTML array in your form, where the array's index is the item id and then just iterate over the array in the php code - <form action="" method="post"> <select name="sel[iTEM_47]"> <option value="abc">option abc</option> <option value="def">option def</option> </select> <select name="sel[iTEM_56]"> <option value="abc">option abc</option> <option value="def">option def</option> </select> <input type="submit"> </form> <?php foreach($_POST['sel'] as $key => $value){ echo "Key: $key, Value: $value<br />"; } ?>
  7. So, you are having a comparison that is failing to match the values in some variables. Why don't you echo (or use var_dump() on) the variables being compared to find what they actually contain. Then troubleshoot why the variables(s) don't have the expected values.
  8. You are also using the syntax for an INSERT query (i.e. INSERT INTO table_name (columns) VALUES (values)) for an UPDATE query. Which type of query are you trying to perform an UPDATE (which looks like UPDATE table_name SET column=value, column=value WHERE ...) or an INSERT?
  9. If you are referring to the last code I posted. It is incomplete and untested because it was only to illustrate how you might accomplish something, based on the limited information you did post, and was not 'actual' working code (at a minimum, the reference to !isset($arr[$seg]) needs to be changed to $hseg and the line setting $hseg needs to be moved to before the if() statement.)
  10. $time + $hours; does not mean anything because you did not assign the result to anything (you have taken algebra in school?)
  11. Php no longer (the setting was turned off by default over 8 years ago in php4.2) populates (and overwrites) regular program variables from the form's $_POST variables. You need to either use the correct $_POST variable (i.e. $_POST['first_name']) or set your existing program variables from the correct $_POST variable (i.e. $first_name = $_POST['first_name'];.) The same is true of any $_POST, $_GET, $_COOKIE, $_SESSION, $_FILES, $_SERVER, and $_ENV variable you might be using. The reason for this is because php made a huge blunder by including $_SESSION variables in this variable overwriting process (and in fact by automatically overwriting any variables with data from different sources) and it allowed hackers to set your session variables by simply sending your script same name post/get/cookie variables and a lot of sites where taken over. Also, if you have any code that uses session_register(), session_is_registered(), or session_unregister(), you will need to make additional changes to use session_start() and the $_SESSION variables.
  12. The method that jcbones posted will work with your column.
  13. The following would give you something to consider on how you could generate all the html and javascript dynamically - $content_a = ""; // HTML href links $content_b = ""; // HTML spans $content_c = ""; // javascript $content_d = ""; // javascript $arr = array(); // array of the data (and keys) $query = "SELECT base, id FROM area"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ $loc = strrpos($row['id'],"_"); $seg = substr($row['id'],0,$loc); $seg = str_replace("SE","",$seg); // the number only if(!isset($arr[$seg])){ $hseg = str_replace("_","-",$seg); // change _ to - in order to match existing html/javascript $arr[$hseg] = ''; // create variable when it does not exist $content_a .= "<a id=\"seg{$hseg}\"><img src=\"images/click{$hseg}.gif\"></a>\n"; $content_b .= "<span class=\"\" id=\"seg{$hseg}text\">--</span>\n"; $content_c .= "\tvar seg{$hseg} = document.getElementById(\"seg{$hseg}text\");\n\tseg{$hseg}.onclick = seg{$hseg}Click;\n"; } $arr[$hseg] .= $row['base']; } // produce the data specific javascript foreach($arr as $key => $value){ $content_d .= "function seg{$key}Click(){document.getElementById('seg1text').innerHTML='$value';}\n"; } echo $content_a; // output the HTML links echo $content_b; // output the span section ?> <script type="text/javascript"> window.onload = pageLoad; // global code function pageLoad() { <?php echo $content_c; ?> } <?php echo $content_d; ?> </script>
  14. The following will (untested) generate all your $segmentx variables from the corresponding SEx data - $query = "SELECT base, id FROM area"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ $loc = strrpos($row['id'],"_"); // find the last _ $seg = substr($row['id'],0,$loc); // get the string upto the last _ $seg = str_replace("SE","segment",$seg); // convert SE to segment if(!isset($$seg)){$$seg = '';} // create empty variable when it does not exist $$seg .= $row['base']; // concatenate data } If you study this, you will also see that you can dynamically generate all the rest of the html and javascript on the page using similar code (no hand typing/hardcoding is needed.) Edit: Actually, you could generate it inside of the if(!isset($$seg)){$$seg = '';} statement when each new id is detected.
  15. The name you gave your's contains a space and it is an array. It produces the following (php converts the space in the name to an under-score in order to make it a valid variable name) - [testbox_] => Array ( [veg] => veggies )
  16. Probably, if you use current recommend php.ini settings, don't use any old deprecated features, and your development system has at least the same php version as your live server (assuming that your live server is at least php5.) About the only thing you should need to worry about is if you use a php language extension that is uncommon and is not present on your live server.
  17. Your code in the 'register' section is redirecting back to that same page upon an error, but is not setting do= in the URL. Is there some reason you have so many redirects in that code instead of just displaying the information you want?
  18. All you need to do is pass data values back and forth. Not php code.
  19. Why do you want to be able to include code from a different server? Putting a URL into an include() statement takes at least 50-100 times longer to execute than including the file directly thorough the file system. Putting a URL into an include() statement also means that your site will be broken any time the site where the include file is located at is also down. Do you want your site to be slow and unnecessarily crippled?
  20. The php code is parsed and executed when the URL is requested (the same as if you browsed to the file being include.) As you have already been told, you only receive any output from the included file. You don't receive the raw php code.
  21. Simple lookup tables are normally used for this kind of thing. Makes adding entries easier and the code is simpler and faster - <?php $User_Serv_Numb = "[email protected]"; // get your value from wherever it is at... $lookup = array(); $lookup["vtext.com"] = "Verizon"; $lookup["messaging.sprintpcs.com"] = "Sprint"; $lookup["tmomail.net"] = "T-Mobile"; $lookup["txt.att.net"] = "AT&T"; $lookup["vmobl.com"] = "Virgin Mobile"; // add more entries here ... list($number, $carrier) = explode("@", $User_Serv_Numb); $carrier = strtolower($carrier); if(isset($lookup[$carrier])){ $Cur_Provider = $lookup[$carrier]; } else { $Cur_Provider = "Unknown Carrier"; } echo "Number: $number, Carrier string: $carrier, Provider: $Cur_Provider<br />"; ?>
  22. pg_escape_string, like its' name indicates is used for escaping string data (i.e. data that is enclosed in quotes in the query.) For numeric data, you must validate that the data is just a number or simply cast it as a number in order to prevent sql injection.
  23. http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  24. Then see this link instead - http://us2.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc
  25. You are apparently reading the sql from a file. See this link - http://us2.php.net/manual/en/info.configuration.php#ini.magic-quotes-runtime
×
×
  • 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.