Jump to content

monkey_05_06

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

monkey_05_06's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Update: I tried just using a for loop instead: for ($i = 0, $set = $sets[$i]; $i < count($sets); $i++, $set = (($i < count($sets)) ? $sets[$i] : NULL)) { It produced exactly the same results. Why? What in processing this command is causing the $sets array to be modified? Edit: Update Mark II - SOLVED! I was being an idiot. In a <b>PRIOR</b> foreach loop I was doing this: <?php foreach ($sets as &$set) { // ... } ?> So $set was still set as a reference to $sets[4]. D'oh! Simply calling unset($set); after I was done with using it by reference resolved the issue!
  2. Hey freaks, long time no see. Not that I was ever very active anyway... So basically I'm doing this: <?php echo "before foreach: " . $sets[4]["scriptName"] . "<br />\n"; foreach ($sets as $set) { echo "before: " . $sets[4]["scriptName"] . "<br />\n"; ?> <input type = "checkbox" name = "include_<?php echo $set["scriptName"]; ?>" <?php $checked = TRUE; if (!isset($_POST["include_{$set["scriptName"]}"])) $checked = FALSE; $query = "UPDATE `users` SET `include_{$set["scriptName"]}` = \"" . (($checked) ? "1" : "0") . "\" WHERE `UID` = \"{$userID}\""; @mysql_query($query); if ($checked) echo "checked "; ?>/> Include <?php echo $set["friendlyName"]; ?>?<br /> <?php if ($checked) print_set($set); echo "after: " . $sets[4]["scriptName"] . "<br />\n"; } ?> And the output I'm getting is very worrying to me. The echo prior to the foreach statement prints the proper value. However as soon as the first "before" statement is being printed, $sets[4]["scriptName"] is immediately set equivalent to $set["scriptName"]. This happens every loop, meaning that by the time it reaches $sets[4], the last index that $sets[4]["scriptName"] is now reading as $sets[3]["scriptName"]. Why is foreach doing this? I've never encountered this before, and as I said it happens immediately when the foreach block is entered. Just in case you were wondering, my print_set function doesn't have any access to the global $sets array, it only takes the parameter for the set to print out.
  3. Because it's 3:15 AM [here]. The more important question is why I would be awake. I guess I just figured it would be easier for me to keep the connection open than having to reopen it. I've got all the pertinent data regarding connecting to MySQL available to both pages...it was really just a matter of lack of experience with PHP...and being extremely tired. I understand now why that line of thinking doesn't really make sense.
  4. Hmmm...actually I can think of a way to work around it now that I know it can't be done. Thanks!
  5. I'm working on a script where I would like a MySQL link identifier to persist over a redirect to another URL. I've tried using session variables to persist the identifier: <?php session_start(); $conn = @mysql_connect("localhost", "username", "pass"); $_SESSION["conn"] = $conn; header("Location: $url"); ?> The variable persists the redirect, but the identifier seems to be getting modified. I know for a fact that it is a valid MySQL link identifier prior to the redirect, however after the redirect it is invalid. Is there any explanation for this???
  6. Ah thank-you. That's exactly what I needed. The function is so descriptively named... I'm sure this has probably been brought up before, sorry for not searching 'round the forums first. I was just being lazy.
  7. When a function returns it simply means that the function stops executing and the script returns to wherever the function was called from. In your example, you've defined the function, but you're never actually calling it. I assume that this is the action script for an HTML form you're using? The solution is, as suzzane said, to use header to redirect...but you should probably also look into how functions work. You don't seem to completely understand the concept.
  8. Is there any function that can be used to interpret a char as an int? AFAIK PHP doesn't distinguish between chars and strings (a char is simply a string with a length of 1 (right?)), so I haven't found/can't think of a way to do this. I imagine I might not be coming across very clear right now, so let me try to explain what I want. I want to convert a char, say 'A' to it's appropriate integer value, i.e., 65. Everything I've tried as far as conversion has simply led to the chars/strings casting to 0. Thanks for any help with this. - monkey
  9. O.O Why the hell is it doing that? I need to take a look at it but my schedule just shut down big time. In other words, I finally got a job! It sucks 'cause now I don't have countless hours on end to spend working on these things...but it's good 'cause now I'll have money. *sigh*
  10. Apparently what I wrote about JS not recognizing the form is an issue with FF (1.5, I'm not sure about 2.0). Seeing as in that snippet I never set a JS var called fullname, that snippet isn't meant to be a standalone example. It should submit the form and then output...something...though I'm not sure what considering the JS var is never set. Possibly an error. Or the fact that the JS var is never set might make it crash. I don't know enough about JS to be sure. [code]<?php   if (!isset($_POST["fullname"])) {   ?> <form action = "" name = "myform" method = "POST">   FORM <!-- Without some output JS won't recognize your form - FF 1.5 -->   <input type = "hidden" name = "fullname" /> </form> <script language = "JavaScript">   var fullname = "John Doe";   document.myform.fullname.value = fullname;   document.myform.submit(); </script> <?php     }   else {     $fullname = $_POST["fullname"];     echo $fullname;     echo $fullname;     }   ?>[/code]
  11. Okay it could just be Firefox 1.5. I don't know if this is any different in FF 2.0. And I'm unfamiliar with "the .forms collection" to which you refer. As I already mentioned, I don't use JS unless it's necessary...and I got it working I just was unsure if this was perhaps a bug. In any case, thanks for the responses.
  12. header requires a full path be sent. Or at least it's supposed to. So: [code]if (isset($_SERVER["HTTP_HOST"])) $host = $_SERVER["HTTP_HOST"]; else $host = $_SERVER["SERVER_NAME"]; $uri = dirname($_SERVER["PHP_SELF"]); if ($uri === "\\") $uri = "/"; if ($uri[strlen($uri) - 1] !== "/") $uri .= "/"; header("Location: http://" . $host . $uri . "include.php?page=newsconfirm");[/code] Also, AFAIK the header function is case-insensitive in regards to the HTTP header choice (i.e., "Location" === "location"). But I could be wrong about this, so it's probably safest just to use "Location".
  13. I was actually hoping someone would solve my challenge mathematically. Oh well. :P Orio your code doesn't...decode properly.
  14. You can use JS to submit a form: [code]<?php   if (!isset($_POST["fullname"])) {   ?> <form action = "<?php echo $_SERVER["PHP_SELF"]; ?>" name = "myform" method = "POST">   FORM <!-- Without some output JS won't recognize your form -->   <input type = "hidden" name = "fullname" /> </form> <script language = "JavaScript">   document.myform.fullname.value = fullname;   document.myform.submit(); </script> <?php     }   else {     $fullname = $_POST["fullname"];     echo $fullname;     echo $fullname;     }   ?>[/code]
  15. You're asking someone to write a script that uses the mysql_connect function? Or what are you asking? [b][EDIT:][/b] You do of course realize that I was joking about "the dreadful extensions"? I just wanted to see if anyone would actually take the time to work it out without these pre-built functions.
×
×
  • 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.