Jump to content

JPark

Members
  • Posts

    75
  • Joined

  • Last visited

    Never

Everything posted by JPark

  1. salathe, Well, I changed the code and tested it and doggonit you are right! While your analogy makes sense NOW, before I was just thinking of them as line breaks in different languages as in "Hi! Hola!" is pretty much the same as "Hola! Hi!" I stand sit corrected. Thanks for clarifying!! Joe
  2. So \n\r is different than \r\n??
  3. I have a php page with a form that, upon submit, generates a text file of the person's choices -- using it as a flat file. I want to start a new line with each entry so I used \n\r as in $line1= $today."^".$_POST['email']."^".$value; foreach ($sector_numbers as $key => $value) { $line = "{$line1}^{$value}\n\r"; $file_write = fwrite($file_handle, $line); } The problem is that my text file shows little boxes instead of new lines (see attachment). Why? How can I fix it? Thanks! Joe [attachment deleted by admin]
  4. Warning: Noob Alert... I am playing around with forms and functions and am getting an error. Here's the form: <form action="functions.php" method="post" > <p>Pick one or more colors:</p> <p><input name="colors[]" type="checkbox" value="red"> Red | <input name="colors[]" type="checkbox" value="orange"> Orange | <input name="colors[]" type="checkbox" value="yellow"> Yellow | <input name="colors[]" type="checkbox" value="green"> Green | <input name="colors[]" type="checkbox" value="blue"> Blue | <input name="colors[]" type="checkbox" value="indigo"> Indigo | <input name="colors[]" type="checkbox" value="violet"> Violet</p> <hr align="left" width="560"> <p><input type="reset" name="Reset" value="Clear"> <input type="submit" name="Submit" value="Submit"></p> </form> and here's the php results page: <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> <tr> <td colspan='2' style='background: #E5E5E5; padding:3px 10px;'> <p style='font-weight:bold; text-align:center;'>You are almost done...</p></td> <tr> <td colspan='2' style='background: #E5E5E5; border-bottom: 1px solid #000; padding:3px 10px;'> <input type="submit" value="ENTER" /></td> </tr> </table> </form> <?php echo "<hr width='200px' align='left'>"; echo "<h4>My Function:</h4>"; $colors = $_POST['colors']; function showColors(&$colors) { foreach ($colors as $key => $value) { echo $key." ==> ".$value." "; } } showColors($colors); ?> The first time I get the results page, I get my selected colors displayed no problem. However, if I click Enter on the results page, I get Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\functions.php on line 87 What am I doing wrong? Thanks! Joe
  5. Windows, I believe.
  6. We need to move all of our documents (pdf, doc, wpd, xls, ppt) off of the web server and into a document management system. Groan. I want to start at the top level and search most -- but not all -- the sub-folders and spit out a nice pretty list of all the documents (and folder location). Anyone have something like that? Thanks!!
  7. That works great! I appreciate your help.
  8. I have an intranet page where people can make comments or suggestions. The powers-that-be would like to review the comments before they are posted on the web page. Right now, I have a form that the 'customer' can fill out. When they hit submit, their name, e-mail and comments get posted to a mysql database and the powers-that-be get an e-mail notification. I would like them to be able to go to an approval page and see all (or one at a time) the posts that are pending approval and be given a choice to approve or delete each comment. I would like to keep it all on one page and, each time a comment is approved or deleted, the page is refreshed with the next comment to approve/delete. Is that an option with php? I know I can query one row at at a time with mysql_fetch_array, but I can't seem to get past the first row. On the other hand, if I display all the comments, the page doesn't refresh right. I will continue to see the comments that have already been deleted or F5 will attempt the same query. This is what I am am working with... $query = 'SELECT * FROM `comments` WHERE `approved` = 1'; //1 = new, 2 = approved $result=mysql_query($query) or die(mysql_error() ); while($row = mysql_fetch_array($result)){ echo $row['name']. " - ". $row['email']; $id = $row['id']; ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="test"> <input name="decision" type="radio" value="approve" /> Approve this comment<br /><input name='id' type='hidden' value='<?php echo $row['id']; ?>' /> <input name="decision" type="radio" value="delete" /> Delete this comment<br /> <input name="Submit" type="submit" /> <input name="Reset" type="reset" value="Reset" /> </form> <?php if ($_POST['decision'] == 'delete') { mysql_query("DELETE FROM comments WHERE id = '$id'"); echo $row['id']."<br />"; } } Any thoughts?
  9. ok... : "hello"; does what I thought it should do to begin with but I don't quite understand what you wrote... Is the problem from the return ($row[4])? Is that why the page is looking for something to be returned?
  10. Ok. Makes a bit of sense... So, why does my page crap out (nothing at all displays) if I change it to return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : echo "hello"; Isn't this saying that $row[4] is true then do sprintf($html, $row[3], htmlentities( $row[1] ) ) but if $row[4] is false then echo "hello"? Joe
  11. I am trying to rework a page written by someone else and there is a function function generate_click_box($row) { $html = <<<HTML <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background:#036; overflow:hidden;"></div> <div id="%1\$s_toggle" style="height:45px; width:191px; margin:0 auto; background:#036; color:#fff; cursor:pointer; font-size:12px; font-weight:bold; text-align:center; padding:0; margin:0;"><div style="padding:2px; vertical-align:middle;">%2\$s</div></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background:#036; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background:#036; overflow:hidden;"></div> HTML ; $html_disabled = <<<HTML <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:45px; width:191px; margin:0 auto; background: #cccccc; color:#036; font-size:12px; font-weight:bold; text-align:center; padding:0; margin:0;"><div style="padding:2px; vertical-align:middle;"> <a href="http://factfinder.census.gov/servlet/EconSectorServlet?caller=dataset&sv_name=*&_SectorId=%1\$s&ds_name=EC0700A1&_lang=en&_ts=272288383987" target="_blank" alt="Click for %2\$s data">%2\$s<br />COMPLETED</a><br /></div></div> <div style="height:2px; font-size:2px; width:189px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:187px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:185px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> <div style="height:1px; font-size:1px; width:181px; margin:0 auto; background: #cccccc; overflow:hidden;"></div> HTML ; return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : sprintf($html_disabled, htmlentities( $row[5] ), htmlentities( $row[1] ) ); } Can someone translate (put into pseudo code) the following piece return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : sprintf($html_disabled, htmlentities( $row[5] ), htmlentities( $row[1] ) ); Thanks! Joe
  12. anyone? Buehler...? Buehler...?
  13. Ok... that was dumb Here's a query of the database: mysql_connect($hostname, $user, $password); @mysql_select_db($database) or die( "Unable to select database"); $sql = "SELECT * FROM shirts WHERE sex='Unisex'"; //EDIT $result=mysql_query($sql); $num=mysql_num_rows($result); mysql_close(); $i=0; echo "<table border='1' width='75%'>"; while ($i < $num) { $item[$i] = mysql_result($result,$i,"item"); $title[$i] = mysql_result($result,$i,"title"); $url[$i] = mysql_result($result,$i,"url"); $imageUrl[$i] = mysql_result($result,$i,"imageUrl"); $alt[$i] = mysql_result($result,$i,"alt"); $sex[$i] = mysql_result($result,$i,"sex"); $shirtType[$i] = mysql_result($result,$i,"shirtType"); echo "<tr>"; echo "<td>".$i."</td>"; echo "<td>".$imageUrl[$i]."</td>"; echo "<td>".$item[$i]."</td>"; echo "<td>".$title[$i]."</td>"; echo "<td>".$shirtType[$i]."</td>"; echo "</tr>"; $i++; } ?> </table> <p>A total of <?php echo $num ?> rows were found.</p> and I do get 23 items http://funny.teamspirittees.com/testing/shirts/sweats/test.php vs the 19 on http://funny.teamspirittees.com/testing/shirts/sweats/funny_sweats_for_guys_and_girls.php. And here's what's even more curious to me. When I log into phpMyAdmin and query the database (SELECT * FROM shirts WHERE sex='Unisex'), I get all 23 sweatshirts. What could be going on? Thanks, Joe
  14. I have a t-shirt web site that I am redesigning. I have a pagination script and thought things were looking good until I found that I was not showing all of my records. 1. Here is a page on the site: http://funny.teamspirittees.com/testing/shirts/sweats/funny_sweats_for_guys_and_girls.php If you count the sweatshirts, you will find 19. However, there are 23 total. 2. Here is a page that lists and counts them: http://funny.teamspirittees.com/testing/shirts/sweats/test.php I don't know why I am missing 3 sweatshirts... it is happening on my other pages as well and I am hoping that fixing this page will help me fix the others. Here's the pagination code: <?php ################################# ### Begin Pagination Coding ##### ################################# $conn = mysql_connect($hostname, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); // find out how many rows are in the table $sql = "SELECT COUNT(shirtType) FROM shirts WHERE sex='Unisex'"; // EDIT $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $columns= 2; // number of shirts to show per page $rowsperpage = 7; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $sql = "SELECT * FROM shirts WHERE sex='Unisex' LIMIT $offset, $rowsperpage"; //EDIT $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); echo "<div class='shirts'>"; $row = mysql_fetch_array($result) or die(mysql_error()); // mysql_fetch_array() returns both an assocative array and a numerically indexed array -- // a combination of the mysql_fetch_row() and the mysql_fetch_assoc() functions // set some basic variables; $tr=0; $flag= 0; $i=0; // run through the all the arrays to break them into individual items that I can reference later while($row = mysql_fetch_object( $result )) { $item[$flag]= $row->item; $title[$flag]= $row->title; $url[$flag]= $row->url; $imageUrl[$flag]= $row->imageUrl; $alt[$flag]= $row->alt; $sex[$flag]= $row->sex; $shirtType[$flag]= $row->shirtType; $flag++; } // find out how many rows we need $totalRows=($flag/2); // begin the table -- 6 rows and 3 columns echo "<table border='0' cellpadding='5' align='center'>"; while ($tr <= $totalRows) { // create the rows $td=1; // each time through, re-start the column counter echo "<tr>"; while ($td <= 2) { //create the columns echo "<td>"; if ($item[$i] == NULL) { break; } echo "<a href='".$url[$i]."'><img src='".strtolower($imageUrl[$i])."' border='0' alt='".$alt[$i]."' /></a>"; // EDIT $i++; echo "</td>\n"; $td++; } echo "</tr>"; $tr++; } echo "</table>"; /****** build the pagination links ******/ // range of num links to show $range = 3; echo "<div align='center'>"; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo "<br /> <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if echo "</div>"; /****** end build pagination links ******/ echo "</div"; echo "</div>"; ############################# ### End Pagination Coding ### ############################# ?> and the code for the test.php page <?php $i = 0; $dir = opendir ("."); while (false !== ($file = readdir($dir))) { if (strpos($file, '.gif',1)||strpos($file, '.jpg',1) ) { echo $i.":<a href='".$file."'>$file</a><br />"; $i++; } } echo "<br /><br />".$i." total items"; ?> What am I missing? Please and thank you! Joe
  15. I am trying to display the contents of an array and having a problem. I am getting an array of states (and state abbreviations) from a form and throwing this into a SESSION array ($_SESSION['states'] = $_POST['states'] Later, I want to echo these choices back, without the state abbreviations. Let's say the customer gives me Maryland-MD, Virginia-VA and Delaware-DE. If I use foreach($_SESSION['states'] as $key=>$value) { $stateName = explode("-",$_SESSION['states']); echo $stateName[0].' <br />'; } echo "</blockquote>"; . I get Notice: Array to string conversion in /vs/webdev/docs/econ/notifyme/state_entry.php on line 469 Array Notice: Array to string conversion in /vs/webdev/docs/econ/notifyme/state_entry.php on line 469 Array What am I doing wrong? What should I do? Thanks, Joe
  16. I hope this helps... <?php /* Description of stateentry.php * * * * * Last modified: 1:13 PM 4/2/2009 **/ include('includes/naics_constants.php'); include('includes/naics.php'); include('includes/cb_text_captcha.php'); $states = ( isset( $_POST['states'] ) && !empty( $_POST['states'] ) ) ? $_POST['states'] : null; $sectors= ( isset( $_POST['sectors'] ) && !empty( $_POST['sectors'] ) ) ? $_POST['sectors'] : null; $email=( isset( $_POST['email'] ) && !empty( $_POST['email'] ) ) ? $_POST['email'] : null; $sys_errors = array(); // errors we may not want to show the user $usr_errors = array(); // errors we should $captcha_match = false; // did the capcha answer pass? Assume no at start function write_the_results($states,$sectors,$email) { $today = date('m.d.Y'); if (!is_null($states) && !is_null($_POST['sectors']) ) { foreach ($_POST['states'] as $temp) { $abbreviations=explode("-",$temp); $line1= $today."^".$_POST['email']."^".$abbreviations[0]."^"; foreach ($_POST['sectors'] as $temp) { $sectorCodes=explode("-",$temp); $line= $line1.$sectorCodes[0]; $file_test='/vs/www/http_db/notify/TEST'. date('Ymd') . 'bystate.txt'; $file_handle = fopen($file_test,'a'); $file_write = fwrite($file_handle, "\r\n$line"); } } } else { } } function write_for_them() { echo "<b>".date('l jS \of F Y, h:i:s A')."<br />"; $states = $_POST['states']; $sectors = $_POST['sectors']; $email = $_POST['email']; foreach($_POST['states'] as $v) { $stateName=explode("-",$v); echo $stateName[1]."<br>"; } foreach($_POST['sectors'] as $w) { $sectorName=explode("-",$w); echo $sectorName[1]."<br>"; } echo "</b>"; } if( isset($_POST) && !empty( $_POST ) ) { // This section pattern matches the POSTED email. // if it complies, use $email_label to show the email address if(!preg_match(EMAIL_REGEX, $_POST['email'])) { $usr_errors[] = USR_ERR_EMAIL; $email_label = '<label for="email" style="' . LABEL_STYLE . '">Email Address:</label> '; $email_input = '<input type="text" id="email" name="email" value="' . $_POST['email'] . '" />'; } else { $email_label = '<span style="' . LABEL_STYLE . '">Email Address:</span> '; $email_input = htmlentities( $_POST['email'] ) . '<input type="hidden" name="email" value="' . $_POST['email'] . '" />'; } $captcha_match = ( isset($_POST['captcha']) )? php_check_captcha($_POST['captcha']) : false; if( isset( $_SESSION[sESS_TXT_CAPTCHA_ANSWER] ) && !$captcha_match ) $usr_errors[] = USR_ERR_CAPCHA; if( $captcha_match && empty($usr_errors) ) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. // // 'a+' - Open for reading and writing; place the file pointer // at the end of the file. If the file does not exist, attempt // to create it. if ( ($file_handle = @fopen(NOTIFY_ME_STORAGE_FILE, 'a+'))!==false ) { //$file_locked = true; //* // waiting until file will be locked for writing (FILE_LOCK_TIMEOUT milliseconds as timeout) $startTime = microtime(); //echo "<pre>$startTime\n"; do { $file_locked = flock($file_handle, LOCK_EX); // If lock not obtained sleep for 10 - 100 milliseconds, to avoid collision and CPU load //var_dump($file_locked); if(!$file_locked) usleep(round(rand(10, 100)*1000)); } while (!$file_locked && (microtime()-$startTime) < FILE_LOCK_TIMEOUT); /**/ // Let's make sure the file exists and is writable first. // lets also make sure that the user information we checked // so far is valid. if( $file_locked && is_writable( NOTIFY_ME_STORAGE_FILE ) ) { foreach($process_order as $key=>$section) { if( isset( $_POST["$key"] ) && !empty( $_POST["$key"] ) ) save_posted_naicscodes($_POST["$key"], $section[0], $section[1], $_POST['email'], $file_handle); } fclose($file_handle); } else $usr_errors[] = 'System is busy.'; } else $sys_errors[] = "The file (" . NOTIFY_ME_STORAGE_FILE . ") is not writable"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- Change date each time you modify the page --> <meta name="DC.date.created" scheme="ISO8601" content="2008-22-04" /> <meta name="DC.date.reviewed" scheme="ISO8601" content="2008-22-04" /> <meta name="DC.language" scheme="DCTERMS.RFC1766" content="EN-US" /> <style type="text/css"> <!-- .forthem { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: medium; color: #333366; } .note { font-style: italic; font-weight: bolder; color: #333366; } .notice { color:red; font-size:120%; } --> </style> <title> NotifyMe :: Thank you! ****</title> <!-- Site wide JS --> <script type="text/javascript" src="/main/javascript/ruthsarian_utilities.js"></script> <script type="text/javascript"> <!-- if ( ( typeof( set_min_width ) ).toLowerCase() != 'undefined' ) { set_min_width( 'page-container' , 783 ); } if ( ( typeof( sfHover ) ).toLowerCase() != 'undefined' ) { event_attach( 'onload' , function () { //sfHover( 'leftmenu' ); sfHover( 'middlemenu' ); } ); } //--> </script> <script type="text/javascript" src="/main/javascript/unlink.js"></script> <script type="text/javascript" src="/main/javascript/jquery.js"></script> <!--End JavaScript Links--> </head> <body> <div id="page-container"> <!-- 44px height --> <!-- newline whitespace removed --> <!-- wordwrap at col 78 --> <noscript> This Javascript highlights what section of the main navigation you are on and unlinks its URL. </noscript> <a name="SKIP2"></a> <div id="outer-column-container"> <div id="inner-column-container"> <div id="source-order-container"> <div id="middle-column"> <div class="inside" style="margin: 1em 2em;"> <h2>NotifyMe :: Confirmation</h2> <? // for each $cat if(!$captcha_match ) { ?> <!-- START NOTIFYME FORM --> <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> <?php //write_the_results($states,$sectors,$email,$today); This will write the results -- but before the CAPTCHA check etc. NOT GOOD! echo "<br>"; $states_count= count($_POST['states']); $sectors_count= count($_POST['sectors']); $combined_count= ($states_count + $sectors_count); if ( ($states_count == 0) || ($sectors_count == 0) ) { echo "<span class='notice'>Please correct the following:"; echo "<ul>"; if ($states_count == 0 ) { echo "<li>You have not selected any states.</li>"; } if ($sectors_count == 0 ) { echo "<li>You have not selected any sectors.</li>"; } echo "</ul></span>"; } if (is_array($states) && isset($states) ) { if ($states_count > 0) { echo "<b>You have selected the following state(s):</b><br><blockquote>"; foreach($_POST['states'] as $v) { if ( in_array($v, $states, TRUE) ) $stateName=explode("-",$v); echo $stateName[1]."<br>"; } echo "</blockquote>"; } else { } } if (is_array($sectors) && isset($sectors) ) { if ($sectors_count > 0) { echo "<b>You have selected the following sector(s):</b><br><blockquote>"; foreach($_POST['sectors'] as $w) { if( in_array($w, $sectors, TRUE) ) { $sectorName=explode("-",$w); echo $sectorName[1]."<br>"; } } echo "</blockquote>"; } else { } } if($combined_count) { if( !isset($_SESSION['seen_captcha_message_once']) ) { ?> <h3>You are almost done...</h3> <p>Please show us that you are a real person and not a web robot by answering the following mathematical question.</p> <p class="note">Please note that your answer must be spelled out (example, 'two' or 'Two') and not numeric (example, '2').</p> <p>Entering the correct answer and clicking Submit Form will complete your registration.</p> <p> </p> <?php $_SESSION['seen_captcha_message_once'] = null; // it's existance, not it's value is being tested. } // end if( !isset($_SESSION['seen_captcha_message_once']) ) ?> <table style="<?=TABLE_STYLE;?>"> <tr> <td style="<?=TABLE_TDROW1_STYLE;?>"><?=$email_label;?></td> <td style="<?=TABLE_TDROW1_STYLE;?>"><?=$email_input;?></td> </tr> <tr> <td style="<?=TABLE_TDROW2_STYLE;?>"><label for="captcha" style="<?=LABEL_STYLE;?>"><?=php_generate_captcha();?></label><br/> <small><?=TXT_CAPTCHA_EXAMPLE;?></small></td> <td style="<?=TABLE_TDROW2_STYLE;?>"><input type="text" id="captcha" name="captcha" /></td> </tr> <tr> <td colspan="2"><input type="submit" value="<?=ENTRY_SUBMIT_TEXT;?>" /></td> </tr> </table> </form> <!-- END NOTIFYME FORM --> <?php } // end if($naics_code_count) else echo '<input type="button" value="Go Back" onclick="history.go(-1); return true;" />'; write_the_results($states,$sectors,$email); ## SENDS FROM HERE -- BUT BEFORE THE CAPTCHA IS CORRECT (TOO EARLY!) } // else if(!$captcha_match || !empty($usr_errors) || !empty($sys_errors) ) else { echo "<span class='forthem'>"; echo "<p> </p>"; echo COMPLETE_RESPONSE_TXT; echo "</span>"; // write_the_results($states,$sectors,$email); *** DOES NOT SEND IT FROM HERE & IT SHOULD *** } // end if(!$captcha_match || !empty($usr_errors) || !empty($sys_errors) ) ?> </body> </html>
  17. That helps but it's STILL not being sent (fwrite). I currently call the function after the CAPTCHA is answered correctly. The COMPLETE_RESPONSE_TXT; is echoed correctly after a successful CAPTCHA but the text file is not appended or created. If I call the function earlier (say, 30 lines up), it works fine. Why???
  18. line 432: echo COMPLETE_RESPONSE_TXT; which comes from an include: define('COMPLETE_RESPONSE_TXT',<<<HTML <span class="forthem"> <p> </p> <p>Thank you for using the NotifyMe System.</p> <p>You should receive a confirmation notice by e-mail within 2 business days.</p> <p>You may also print this page for your records by using the button below.</p><br /> <form><input type="button" value=" Print this page " onclick="window.print();return false;" /></form> </span> HTML );
  19. For example... function write_the_results($states,$sectors,$email,$today) { $states = ( isset( $_POST['states'] ) && !empty( $_POST['states'] ) ) ? $_POST['states'] : null; $sectors= ( isset( $_POST['sectors'] ) && !empty( $_POST['sectors'] ) ) ? $_POST['sectors'] : null; $email=( isset( $_POST['email'] ) && !empty( $_POST['email'] ) ) ? $_POST['email'] : null; $today = date('m.d.Y'); echo "<b>For testing only: </b><br />"; $line1= $today." ^ ".$states." ^ ".$sectors." ^ ".$email; echo $line1."<br>"; } And later... } elseif( $captcha_match && empty($usr_errors) ) { echo "<br /><b>".$_POST['email']."</b>"; echo "<span class='forthem'>"; echo COMPLETE_RESPONSE_TXT; echo "</span>"; write_the_results($today, $states, $sectors, $email); } And I get... Notice: Undefined variable: today in /vs/webdev/docs/econ/notifyme/state_entry2.php on line 432 For testing only: 08.03.2009 ^ ^ ^ [email protected] So, I get an error on $today even though it shows up like I wanted, I don't get anything for $states or $sectors and I get the email correctly (matching $_POST['email']). What am I doing wrong? What do I do to fix it? Thanks.
  20. I am new to functions and would appreciate some guidance... I have a page that is getting some values from a form ($_POST['states'], $_POST['sectors'] and $_POST['email'] -- the first two values are arrays. I want to create a function to run the values through a loop, perform some checks and then fwrite the values to a text file on another server. However, I only want to run this function after the user has correctly answered a CAPTCHA. For the life of me, I cannot figure this out. I can do some very simple functions but this one has me running in circles. Can anyone help shed some light? Please and thank you!! Joe
  21. anyone?
  22. You asked for it... <?php /* Description of stateentry.php * * * * * Last modified: 1:13 PM 4/2/2009 **/ include('includes/naics_constants.php'); include('includes/naics.php'); include('includes/cb_text_captcha.php'); $states = ( isset( $_POST['states'] ) && !empty( $_POST['states'] ) ) ? $_POST['states'] : null; $sectors= ( isset( $_POST['sectors'] ) && !empty( $_POST['sectors'] ) ) ? $_POST['sectors'] : null; $email=( isset( $_POST['email'] ) && !empty( $_POST['email'] ) ) ? $_POST['email'] : null; $sys_errors = array(); // errors we may not want to show the user $usr_errors = array(); // errors we should $captcha_match = false; // did the capcha answer pass? Assume no at start function write_the_results() { $today = date('m.d.Y'); $states = ( isset( $_POST['states'] ) && !empty( $_POST['states'] ) ) ? $_POST['states'] : null; $sectors= ( isset( $_POST['sectors'] ) && !empty( $_POST['sectors'] ) ) ? $_POST['sectors'] : null; $email=( isset( $_POST['email'] ) && !empty( $_POST['email'] ) ) ? $_POST['email'] : null; if (!is_null($states) && !is_null($_POST['sectors']) ) { echo "<b>For testing only: </b><br />"; foreach ($_POST['states'] as $temp) { $abbreviations=explode("-",$temp); $line1= $today." ^ ".$_POST['email']." ^ ".$abbreviations[0]." ^ "; foreach ($_POST['sectors'] as $temp) { $sectorCodes=explode("-",$temp); $line= $line1.$sectorCodes[0]; $file_test='/vs/www/http_db/notify/TEST'. date('Ymd') . 'bystate.txt'; $file_handle = fopen($file_test,'a'); $file_write = fwrite($file_handle, "\r\n$line"); echo $line."<br>"; } } } else { } } function write_for_them() { echo "<b>".date('l jS \of F Y, h:i:s A')."<br />"; $states = $_POST['states']; $sectors = $_POST['sectors']; $email = $_POST['email']; foreach($_POST['states'] as $v) { $stateName=explode("-",$v); echo $stateName[1]."<br>"; } foreach($_POST['sectors'] as $w) { $sectorName=explode("-",$w); echo $sectorName[1]."<br>"; } echo "</b>"; } if( isset($_POST) && !empty( $_POST ) ) { // This section pattern matches the POSTED email. // if it complies, use $email_label to show the email address if(!preg_match(EMAIL_REGEX, $_POST['email'])) { $usr_errors[] = USR_ERR_EMAIL; $email_label = '<label for="email" style="' . LABEL_STYLE . '">Email Address:</label> '; $email_input = '<input type="text" id="email" name="email" value="' . $_POST['email'] . '" />'; } else { $email_label = '<span style="' . LABEL_STYLE . '">Email Address:</span> '; $email_input = htmlentities( $_POST['email'] ) . '<input type="hidden" name="email" value="' . $_POST['email'] . '" />'; } $captcha_match = ( isset($_POST['captcha']) )? php_check_captcha($_POST['captcha']) : false; if( isset( $_SESSION[sESS_TXT_CAPTCHA_ANSWER] ) && !$captcha_match ) $usr_errors[] = USR_ERR_CAPCHA; if( $captcha_match && empty($usr_errors) ) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. // // 'a+' - Open for reading and writing; place the file pointer // at the end of the file. If the file does not exist, attempt // to create it. if ( ($file_handle = @fopen(NOTIFY_ME_STORAGE_FILE, 'a+'))!==false ) { //$file_locked = true; //* // waiting until file will be locked for writing (FILE_LOCK_TIMEOUT milliseconds as timeout) $startTime = microtime(); //echo "<pre>$startTime\n"; do { $file_locked = flock($file_handle, LOCK_EX); // If lock not obtained sleep for 10 - 100 milliseconds, to avoid collision and CPU load //var_dump($file_locked); if(!$file_locked) usleep(round(rand(10, 100)*1000)); } while (!$file_locked && (microtime()-$startTime) < FILE_LOCK_TIMEOUT); /**/ // Let's make sure the file exists and is writable first. // lets also make sure that the user information we checked // so far is valid. if( $file_locked && is_writable( NOTIFY_ME_STORAGE_FILE ) ) { foreach($process_order as $key=>$section) { if( isset( $_POST["$key"] ) && !empty( $_POST["$key"] ) ) save_posted_naicscodes($_POST["$key"], $section[0], $section[1], $_POST['email'], $file_handle); } fclose($file_handle); } else $usr_errors[] = 'System is busy.'; } else $sys_errors[] = "The file (" . NOTIFY_ME_STORAGE_FILE . ") is not writable"; } } /**/ ?> <html> <head> </head> <body> <h2>NotifyMe :: Confirmation</h2> <?php // for each $cat if(!$captcha_match ) { ?> <!-- START NOTIFYME FORM --> <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> <?php // write_the_results(); This will write the results -- but before the CAPTCHA check etc. NOT GOOD! echo "<br>"; $states_count= count($_POST['states']); $sectors_count= count($_POST['sectors']); $combined_count= ($states_count + $sectors_count); if ( ($states_count == 0) || ($sectors_count == 0) ) { echo "<span class='notice'>Please correct the following:"; echo "<ul>"; if ($states_count == 0 ) { echo "<li>You have not selected any states.</li>"; } if ($sectors_count == 0 ) { echo "<li>You have not selected any sectors.</li>"; } echo "</ul></span>"; } if (is_array($states) && isset($states) ) { if ($states_count > 0) { echo "<b>You have selected the following state(s):</b><br><blockquote>"; foreach($_POST['states'] as $v) { if ( in_array($v, $states, TRUE) ) $stateName=explode("-",$v); echo $stateName[1]."<br>"; } echo "</blockquote>"; } else { } } if (is_array($sectors) && isset($sectors) ) { if ($sectors_count > 0) { echo "<b>You have selected the following sector(s):</b><br><blockquote>"; foreach($_POST['sectors'] as $w) { if( in_array($w, $sectors, TRUE) ) { $sectorName=explode("-",$w); echo $sectorName[1]."<br>"; } } echo "</blockquote>"; } else { } } if($combined_count) { if( !isset($_SESSION['seen_captcha_message_once']) ) { ?> <h3>You are almost done...</h3> <p>Please show us that you are a real person and not a web robot by answering the following mathematical question.</p> <p class="note">Please note that your answer must be spelled out (example, 'two' or 'Two') and not numeric (example, '2').</p> <p>Entering the correct answer and clicking Submit Form will complete your registration.</p> <p> </p> <?php $_SESSION['seen_captcha_message_once'] = null; // it's existance, not it's value is being tested. } // end if( !isset($_SESSION['seen_captcha_message_once']) ) ?> <table style="<?=TABLE_STYLE;?>"> <tr> <td style="<?=TABLE_TDROW1_STYLE;?>"><?=$email_label;?></td> <td style="<?=TABLE_TDROW1_STYLE;?>"><?=$email_input;?></td> </tr> <tr> <td style="<?=TABLE_TDROW2_STYLE;?>"><label for="captcha" style="<?=LABEL_STYLE;?>"><?=php_generate_captcha();?></label><br/> <small><?=TXT_CAPTCHA_EXAMPLE;?></small></td> <td style="<?=TABLE_TDROW2_STYLE;?>"><input type="text" id="captcha" name="captcha" /></td> </tr> <tr> <td colspan="2"><input type="submit" value="<?=ENTRY_SUBMIT_TEXT;?>" /></td> </tr> </table> </form> <!-- END NOTIFYME FORM --> <?php } // end if($naics_code_count) else echo '<input type="button" value="Go Back" onclick="history.go(-1); return true;" />'; } // else if(!$captcha_match || !empty($usr_errors) || !empty($sys_errors) ) else { write_the_results(); // This doesn't seem to write the results at all? echo "<span class='forthem'>"; // write_for_them(); echo "<p> </p>"; echo COMPLETE_RESPONSE_TXT; echo "</span>"; } // end if(!$captcha_match || !empty($usr_errors) || !empty($sys_errors) ) ?> </body> </html>
  23. But why can I call the function pretty much anywhere else on the page and it works but not here?
×
×
  • 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.