Jump to content

phpchick

Members
  • Posts

    73
  • Joined

  • Last visited

Everything posted by phpchick

  1. Yes that worked! That was actually the first thing I tried and it didn't work (then) but now it works. so yay I must have had a typo in there when I did it the first time. Thanks Mr Marcus.
  2. I have this super simple function function getstockstats($stocksymbol) { include_once('ii-prediction-log-widget/class.yahoostock.php'); $objYahooStock = new YahooStock; $objYahooStock->addFormat("snl1d1t1cvc1p2"); $objYahooStock->addStock("$stocksymbol"); foreach( $objYahooStock->getQuotes() as $code => $stock) { echo $stock[0]; } } when I use the function, I pass it a symbol like this getstockstats("aapl"); I want this line $objYahooStock->addStock("$stocksymbol"); to receive the variable (aapl), instead, its reading it as $stocksymbol I know there is a way to exit that but I can't for the life of me figure it out because it is so hard to explain that portion. Can someone help me? I've tried wrapping it in {} like this $objYahooStock->addStock("{$stocksymbol}"); but that did not work either. Thank you!! <3
  3. The code below works echo '<script language="javascript">'; echo 'top.location.href = "/breaking-news/bsnewsstorygoeshere/";'; echo '</script>'; this also works echo '<script language="javascript">'; echo 'top.location.href = "http://anywebsite.com";'; echo '</script>'; the problem, is I have a URL listed in a url variable that can be retreived via $_GET['url'] my question is how to get that variable into the above code? I've tried echo '<script language="javascript">'; echo "top.location.href = \"$_GET['url']\";"; echo '</script>'; but that doesnt seem to work, can anyone advise?
  4. so the user is reading a story, to finish reading he has to click a link that redirects them to the signup page. <?php session_start(); $beginurl = $_SERVER['HTTP_REFERER']; $_SESSION['beginurl'] = $beginurl; echo $_SESSION['beginurl']; ?> <html> <head> </head> <body> <script type="text/javascript"><!-- location.replace("http://www.mysite.com/members/"); //--></script> </body> </html> When they get to the second page, they have to click a link that opens up a modal. this is the code that runs when they hit the register button session_start(); $beginurl = $_SESSION['beginurl']; $beginurl= (isset($_SESSION['beginurl'])) ? $_SESSION['beginurl'] : 'Error'; if( $_SESSION['status'] ='authorized') $_SESSION['$makemodal'] = 0; //sends the user to the page upon successful password credential if(!isset($_SESSION['SESS_USERID'])||(trim($_SESSION['SESS_USERID']=='admin'))) { echo '<script language="javascript">'; echo "top.location.href = $beginurl"; echo '</script>'; exit(); } Am I passing this variable correctly? and I'm not sure if the top.location.href towards the bottom is correct either, right now after I hit the register button I'm redirected to a blank page where the url is, "http://www.mysite.com/function Error() { [native code]}"
  5. problems with line 9 and 10.... I'm worried about line 9 and 10 because I took it from this example... in the example, they manually specify that if the number is greater than 1, to "throw new Exception("Value must be 1 or below");" which is why they use catch(Exception $e) later on in the script. In my code, I just use it because its what I saw in the example. But I'm not sure how to handle it otherwise?
  6. the only thing I'm worried about in my implementation is whether or not the code will continue the do-while loop if it hits the error. Can anyone verify this? do { try { $result = $wsdl->GetLastRealTimeMetalQuotes($param); $catcherror = 0; echo "it connected"; echo"\n"; } catch (Exception $e) { echo 'Message: ' .$e->getMessage(); $catcherror =1; echo "it didn't connect"; } } while ($catcherror == 1);
  7. will this work? basically I want the line that calls the web service to loop whenever it hits the fatal error. i want it to keep trying to connect until it is successful and then move on to the rest of the code. do { try { $result = $wsdl->GetLastRealTimeMetalQuotes($param); } catch (Exception $e) { echo 'Message: ' .$e->getMessage(); $catcherror =1; } } while ($catcherror != 1); //the rest of the program goes here
  8. since my error is "Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in /root/fuzzy/htmlmain9.php:126" does that mean there's nothing that can be done but manually restart it? ///////// nevermind, it's only uncaught because i didn't catch it i believe. - duh
  9. $service_header = new SoapHeader('http://www.example.com/services/', 'Header', array("Username" => "usernamegoeshere", "Password" => "passwordgoeshere", "Tracer" => "")); $wsdl = new soapclient('http://www.examples.com/f00.asmx?WSDL'); // attach SOAP header $wsdl->__setSoapHeaders(array($service_header)); // call the service: pass the parameters and name of the operation $param = array('Types' => "XAU", 'Currency' => "USD"); $result = $wsdl->GetLastRealTimeMetalQuotes($param);
  10. Not sure I understand. When this happens I just restart the code and it runs perfectly? If I can just do this everytime its okay, just not sure how to program it to do that?
  11. Here is one example of a fatal error that occurs. When this happens I just restart the code manually and it will work. i think its just temporary connection issues. Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /root/file.php:285 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://www.xign...', 'http://www.xign...', 1, 0) #1 [internal function]: SoapClient->__call('GetLastRealTime...', Array) #2 /root/file.php(285): SoapClient->GetLastRealTimeMetalQuotes(Array) #3 {main} thrown in <b>/root/file.php on line 285 line 285 is $result = $wsdl->GetLastRealTimeMetalQuotes($param); // this is calling a web service not sure how implement the recommended fixes in this step. when the fatal error occurs, does it spit out a value somewhere? I saw on php.net that E_ERROR (integer) is a predefined constant for fatal errors. Does this mean that I do... do { the entire code } while ( E_ERROR () =! 1 ) I'm just not familiar with the error handling syntax
  12. here's the code if other people want to use this, or learn do { $fh = fopen($ftp_path, 'w', 0, $stream_context); // Opens the file for writing and truncates it to zero length // Writes contents to the file if ( $change > 0 ) fputs($fh, "$tuff to write"); //the case if change is positive else fputs($fh, "$tuff to write"); //the case if change is negative fclose($fh); // Closes the file handle $check = file_get_contents ("$ftp_path"); echo "size of written html: "; echo strlen($check); echo "\n\n"; } while ( strlen($check) < 100 );
  13. I see the problem. the file is closed off inside the loop. but the file isn't opened inside the loop. so when it it hits that error, and executes inside the loop, it can't open up the file. Thank you kicken It looks like the program is functioning properly now.
  14. kicken: I did what you suggest and put the fclose before the get_file_contents so that it looks like this. if ($fh = fopen($ftp_path, 'w', 0, $stream_context)) { // Writes contents to the file do{ if ( $change > 0 ) fputs($fh, "stuff that goes into the remote html file"); //line 224 else fputs($fh, "stuff that goes into the remote html file"); //the case if change is negative // Closes the file handle fclose($fh); //line 231 $check = file_get_contents ("$ftp_path"); echo strlen($check); } while ( strlen($check) < 100 ); } else { die('Could not open file.'); } It runs fine until it the error occurs and the html file is less than 100 in length. then this error occurs: Warning: fputs(): 422 is not a valid stream resource in <b>/root/fuzzy/htmlmain8.php on line 224 Warning: fclose(): 422 is not a valid stream resource in <b>/root/fuzzy/htmlmain8.php</b> on line 231 size of written html: 0 line 224 is this line: fputs($fh, "stuff to be written"); //the case if change is positive and line 231 is this line: fclose($fh); //where I moved the fclose above the file_get_contents
  15. I keep getting errors that are associated with one-off and one-time occurrences. I want to tell the script to just restart itself from the beginning if it encounters any type of error, whether it by a fatal error, or any other kind. is there a way to do this?
  16. I think i found the solution. basically what i decided to do is I put the entire writing portion into a do-while loop. that is: do the writing portion while the length of the html file is less than 100. (because I know my html should always be more than 100, if its less, it means the blank error occured). and since it is a do-while loop, it will run once, and then cancel itself out at the end because the while condition is evaluated at the end of the loop. unless it is blank, then it the loop to try to rewrite the file will initiate. if ($fh = fopen($ftp_path, 'w', 0, $stream_context)) { // Writes contents to the file do{ if ( $change > 0 ) fputs($fh, "stuff that goes into the remote html file"); //the case if change is positive else fputs($fh, "stuff that goes into the remote html file"); //the case if change is negative $check = file_get_contents ("$ftp_path"); echo strlen($check); } while ( strlen($check) < 100 ); } else { die('Could not open file.'); } // Closes the file handle fclose($fh);
  17. it is continuously writing data. its the price of gold. and it updates the price every 10 seconds or so.
  18. I have a php script on a server writing to an html file on a remote server. I'm using the following combination of fopen and fputs. The problem is that once out of maybe every 10 or 15 writes to the file, the file that is written is blank with nothing in it. Has anyone here had experience with this before? The file is fixed the next time it writes to it. this code is within a loop that runs every 10 seconds. // Allows overwriting of existing files on the remote FTP server $stream_options = array('ftp' => array('overwrite' => true)); // Creates a stream context resource with the defined options $stream_context = stream_context_create($stream_options); // Opens the file for writing and truncates it to zero length if ($fh = fopen($ftp_path, 'w',0, $stream_context)) { if ( $change > 0 ) fputs($fh, "the contents of the html file is here"); //the case if change is positive else fputs($fh, "the contents of the html file is here"); //the case if change is negative // Closes the file handle fclose($fh); } else { die('Could not open file.'); }
  19. Oh I see now, since the loop will be true forever, it will cycle back to the beginning everytime. right, your code is much better than what I had in mind.
  20. I'm writing to an html file. If its during stock market hours write X, if its not during market hours write Y. while (true){ if (/* 9:30am - 4pm, monday through thursday */){ bodyOfLoop1(); } else { bodyOfLoop2(); } } kicken: wouldn't your code stop running after it goes back into market hours for the first time? i don't see how it knows to go back to bodyofloop1() after bodyofloop2() is executed in the else portion of the if.
  21. I have two while loops that should run infinitely. while loop #1 runs during 9:30am - 4pm, monday through thursday while loop #2 runs when its not 9:30am-4pm, monday through thursday. $hourmin = date("Gi", time(now)); $current = getdate(); while ( $hourmin > 829 && $current[hours] < 15 && $current[wday] > 0 && $current[wday] < 6 ): // while loop #1 while ( $hourmin < 830 || $current[hours] > 14 || $current[wday] = 0 || $current[wday] = 6 ): // while loop #2 as you can see the while condition is the easy part, but I'm not sure how to set this up. I was going to do this using a combination of if statements and the goto function but my version of php does not support goto. I just want it to switch back and forth between these these two while statements infinitely. Is this possible in PHP?
  22. i fixed it with this $changequery = sprintf("select $goldprice-price as change1 from goldclose order by dayid desc limit 1"); $changeget = mysql_query($changequery); $changearray = mysql_fetch_array($changeget); printf("$changearray[0]"); the problem was change can't be used as the name of a column.
  23. When I run 'select 1700-price as blah from goldclose as t2 order by dayid desc limit 1' by itself in mysql I get a numerical result: one row, one column. In my php script, the 1700 is actually a variable. so here it is $changequery = sprintf("select $goldprice-price as change from goldclose order by dayid desc limit 1"); $change = mysql_query(changequery); while ($row = mysql_fetch_array($change)) { printf("$row[0]"); } mysql_free_result($changeresult); I get the following error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 99 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 103 Not sure why? All i want is to get the result of that select statement into a variable such as $change
  24. Hi, I have a website that autoloads a modal window. The behavior currently is that it waits until the entire page is loaded before the modal pops up. Sometimes this can take a long time to load. I was wondering if there was a way to make the modal pop up immediately, regardless of whether the page is done loading. The page can finish loading while the modal is up obviously. This is what I am currently using to call the modal. <body <?php echo "onload='$(\"a#various3\").trigger(\"click\");' "; ?> >
×
×
  • 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.