Jump to content

phpJoeMo

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Everything posted by phpJoeMo

  1. So, this is probably more suited for a blog somewhere. But I felt like sharing my view on the matter. Speaking in terms of performance and web app responsiveness: I think within 2-5 years, it will be pointless to use jQuery. ... ... Following are my reasons why: The main selector engine"Sizzle" really doesn't do too much more than the .querySelectorAll() native javascript method. .each() is a lot slower than the native .every(). Chrome has pushed javascript onto the forefront with faster processing speed etc., IE continues losing market share in the former's favor, forcing IE to think standards. Aside from the animations, which aren't entirely necessary and can sometimes become more annoying than anything, jQuery and the like really just solve a bunch of browser compatibility issues that aren't going to be as bad in the near future. Just some thoughts. What are yours?
  2. Try this code: <?php mysql_connect ("localhost", "3333","33333333") or die (mysql_error()); mysql_select_db ("Customers"); $term = (isset($_POST['term'])?$_POST['term']:null); $sql = mysql_query("select * from storage where box_number = '$term'"); $row = mysql_fetch_array($sql); if(count($row)){ while ($row){ echo 'box_num: '.$row['box_number']; echo '<br/> dept: '.$row['Department']; echo '<br/> company: '.$row['Company']; echo '<br/> status: '.$row['status']; echo '<br/> location: '.$row['location']; echo '<br/> description: '.$row['box_desc']; } } else { echo 'There are no hamsters in the field! Feel free to let the cat out.'; } echo '<br/><br/>'; ?>
  3. Sorry didn't realize the bold didn't work inside the code. You can alter the order like so: RewriteCond %{QUERY_STRING} ^city=([^/]*)&state=([^/]*)&country=([^/]*) RewriteRule ^.*$ /%3/%2/%1/
  4. Alternatively you could reverse the order like so: RewriteCond %{QUERY_STRING} ^city=([^/]*)&state=([^/]*)&country=([^/]*) RewriteRule ^.*$ [b] /%3/%2/%1/[/b]
  5. I think something along the lines of this will do what you want: Put the following ABOVE your rewrite rules & conditions: RewriteBase / Then add this anywhere in your rules & conditions: RewriteCond %{QUERY_STRING} ^city=([^/]*)&state=([^/]*)&country=([^/]*) RewriteRule ^.*$ /%1/%2/%3/ Let me know how it works out.
  6. Were you able to figure it out? If so can you please mark the thread as solved? Thanks.
  7. Hi, I cleaned up the HTML. Be sure to use CSS for all stying. Avoid font tags to the greatest extent possible!!! I have it configured to echo out a sample query. You'll need to add the WHERE clause to the UPDATE query: <?php $q=$_GET["q"]; $con = mysql_connect('my-host', 'my_user', 'my_pwd'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); /*MAKE SURE TO VALIDATE ALL DATA!*/ function Check_post($val) { return (isset($_POST[$val])?$_POST[$val]:false); } /*THIS IS CONFIGURED TO DEMAND ALL INPUT*/ $inputs = array( 'FNAME', 'LNAME', 'ADDR1', 'ADDR2', 'CITY', 'STATE', 'ZIP', 'PHONE1', 'PHONE2', 'PHONE3', 'EMAIL' ); $valuesToUpdate[]; foreach ($inputs as $key) { $postValue = Check_post($key); if ( $postValue ) { $valuesToUpdate[$key] = $postValue } } $setData = ''; if (count($valuesToUpdate)) { $c = 0; foreach ( $valuesToUpdate as $field => $value ) { $setData .= ($c>0?', ':'')."$field = '$value'"; ++c; } } if ( $setData ) { echo " UPDATE mytable SET $setData "; } $sql="SELECT * FROM daterange WHERE DEND > DATE(NOW()) AND STATUS='A' AND MONTH = '".$q."' ORDER BY RID, DATE, SITE"; $result = mysql_query($sql); // Determine the number of reservation dates $rows = mysql_fetch_array($result); ob_start(); ?> <b>Select Your Reservation:</b><br> <form action="resersend.php" method="post"> <select name="RID"> <option value="">Choose One</option> <?php foreach ($rows as $b) { $RID = $b["RID"]; $DATE = $b["DATE"]; $SITE = $b["SITE"]; $PRICE = $b["PRICE"]; echo "<option value='$RID'>$DATE, $SITE, $PRICE</option>"; } ?> </select> <input type="text" name="FNAME" size="50" maxlength="50" tabindex="1"/><br> Last Name: <input type="text" name="LNAME" size="50" maxlength="50" tabindex="2"/><br> Address Line 1: <input type="text" name="ADDR1" size="50" maxlength="50" tabindex="3"/><br> Address Line 2: <input type="text" name="ADDR2" size="50" maxlength="50" tabindex="4"/><br> City: <input type="text" name="CITY" size="50" maxlength="50" tabindex="5"/><br> State (abbrev.): <input type="text" name="STATE" size="2" maxlength="2" tabindex="6"/><br> Zip Code: <input type="text" name="ZIP" size="5" maxlength="5" tabindex="7"/><br> Contact Phone Number: (<input type="text" name="PHONE1" size="3" maxlength="3" tabindex="8"/>)<br> <input type="text" name="PHONE2" size="3" maxlength="3" tabindex="9"/><br> <input type="text" name="PHONE3" size="4" maxlength="4" tabindex="10"/><br> Email: <input type="text" name="EMAIL" size="50" maxlength="50" tabindex="11"/></label><br> <input type="submit" value="Book Now!" name="submit"><br> <input type="reset" value="reset" name="reset"> </form> <?php echo ob_get_contents(); ob_clear(); ?> ALSO:: Never allow any $_GET or $_POST Data into a query string WITHOUT sanitizing / filtering it!
  8. Wow, need I say it again, Wow. I am continually amazed at how badly Godaddy falls short every time of being able to answer my questions. Check out this simple script: $sock = fsockopen("smtpout.secureserver.net", 80, $errno, $errstr, 60); if (!$sock) die("$errstr ($errno)\n"); fwrite($sock,"ehlo\r\n"); fwrite($sock,"auth login\r\n"); fwrite($sock,"c3VwcG9ydEsdfdsdfscGxhY2UuY29t\r\n"); fwrite($sock,"aFVoZWpzdsdfd2g=\r\n"); fwrite($sock,"mail from: <me@myaddress.com>\r\n"); fwrite($sock,"rcpt to:<someone@theiraddress.com>\r\n"); fwrite($sock,"data\r\n"); fwrite($sock,"From: 'me' <me@myaddress.com>\r\n"); fwrite($sock,"To: 'someone' <someone@theiraddress.com>\r\n"); fwrite($sock,"Subject: This is a test!\r\n"); fwrite($sock,"\r\n"); fwrite($sock,"asdfasfffffffffzzzzzzzzzzzzdfasdf\r\n"); fwrite($sock,"\r\n"); fwrite($sock,".\r\n"); fwrite($sock,"quit\r\n"); $a = stream_get_line ($sock,55555); var_dump($a)."\n"; This comunicates irc protocol to my Godaddy email account. I created this for testing purposes. Tyring to create a newsletter app. THE SCRIPT RUNS FLAWLESSLY FROM MY LOCAL SERVER!!!! After concluding that the problem was on Godaddy's end, I called them up. After getting the usual back and forth garbage about how the problem is with my script, and they can't help me with that, I finally made if very clear: "I will bow a thousand times if you can do this one thing for me..." (speaking to the rep) "ask the admins this very simple and straight forward question: CAN FSOCKOPEN REFERENCE ANY OTHER HOST OTHER THAN RELAY-HOSTING.SECURESERVER.NET?" After another 5 minute hold this is the response I got: "Not an yes/ or no answer, all I got was: You can certainly try..." Silence. I can certainly try? That has got to be the dummest response I have ever heard to a simple question any admin should be able to answer. SO HERE IS MY QUESTION FOR YOU, FELLOW PHPFREAKS ... What is your preferred hosting solution?
  9. Sometimes I wonder why I stay with Godaddy ?????!!! Anyway, here is the script that I currently have: require 'Zend/Mail.php'; require 'Zend/Mail/Transport/Smtp.php'; $config = array('plain' => 'login', 'name' => 'name', 'username' => 'myuser', 'password' => 'mypass', 'port' => 80); $transport = new Zend_Mail_Transport_Smtp('smtpout.secureserver.net', $config); Zend_Mail::setDefaultTransport($transport); $mail = new Zend_Mail(); $mail->setBodyText('This is the text of the mail.'); $mail->setFrom('myemail', 'myname'); $mail->addTo('to@example.com', 'name'); $mail->setSubject('TestSubject'); $mail->send($transport); now obviously I'm replacing values like 'myname' etc with the correct ones. Here's my question, why am I getting the following error msg: Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'Could not read from smtpout.secureserver.net' in /my/path/Zend/Mail/Protocol/Abstract.php:385 Stack trace: #0 /my/path/Zend/Mail/Protocol/Abstract.php(415): Zend_Mail_Protocol_Abstract->_receive(300) #1 /my/path/Zend/Mail/Protocol/Smtp.php(199): Zend_Mail_Protocol_Abstract->_expect(220, 300) #2 /my/path/Zend/Mail/Transport/Smtp.php(200): Zend_Mail_Protocol_Smtp->helo('biztoolplace') #3 /my/path/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail() #4 /my/path/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail)) #5 /my/path/mail.php(19): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp)) #6 {main} thrown in /my/path/Zend/Mail/Protocol/Abstract.php on line 385
  10. OK, so I learned how to read the classes. Basically the seperated words in the class definitions are file path with file name at the end of class name. IE: class 'Zend_Mail_Transport_Smtp' path to file 'Zend/Mail/Transport/Smtp.php'
  11. Hi all, I'm getting started with zend and I would like to begin by sending a simple stmp authenticated email. I've search the documentation, only I can't seem to find which file to include when I want to use the framework. Here is my sample code: <?php $config = array('auth' => 'login', 'username' => 'myUserNameGoesHere', 'password' => 'myPasswordGoesHere'); $transport = new Zend_Mail_Protocol_Smtp('smtpout.secureserver.net', 80, $config); $mail = new Zend_Mail(); $mail->setBodyText('This is the text of the mail.'); $mail->setFrom('my@email.here', 'my name here'); $mail->addTo('somerecip@somedom.com', 'somerecip'); $mail->setSubject('TestSubject'); $mail->send($transport); ?> Any thoughts?
  12. Hey salman, I don't mind being of help. Jons does have a point though. Learning these topics will take a lot of time, trial & error, and studying. You can do it though! I would start off by installing xampp if you haven't already done so, you can create databases and tables fairly easy with phpmyadmin. Study the mysql functions in the php docs function->database extensions -> mysql reference. Try out some code, read, learn, try some more, when you run into a wall, come back and start a new thread. Good Luck!
  13. OK, In the example above we created an 'associative array'. This basically means that we are identifying the values of the array with 'keys' that contain string values. IE $conversions['USD'] = 1 in our case above. We created a function that accepts 4 arguments as parameters: function converter($need, $have, $value, $conversionArray) $need is the key value we want. $have is the key value we have. $value is the amount we have. $conversionArray is the array containing the Keys / values of our conversions. you can read more at http://www.php.net/manual/en/language.types.array.php, however I recommend you download the files locally for quicker reference: http://www.php.net/download-docs.php I have a .chm file on my desktop I love having it there!
  14. Sorry, did some error testing at the CLI, This works great: $conversions = array( 'USD'=>1, 'GBP'=>1.62343, 'CAD'=>1.02554 ); function br() { echo '<br/>'; } function converter($need, $have, $value, $conversionArray) { return (($conversionArray[$have] / $conversionArray[$need]) * $value); } var_dump($conversions); br(); echo converter('USD', 'GBP', 5.25, $conversions); br(); echo converter('GBP', 'USD', 5.25, $conversions); br(); echo converter('GBP', 'CAD', 5.25, $conversions);
  15. OK, so I found these sample rates here: http://www.x-rates.com/ You basically need either an array, or a table in mysql to store the conversion rates. I think an array would work nicely: $conversions = array( 'USD'=>1, 'GBP'=>1.62343, 'CAD'=>1.02554 ); Having that, you then would neet some way to convert the data. Probably a function: function br() { echo '<br/>'; } function converter($need, $have, $value, $conversionArray) { ($conversionArray[$have] / $conversionArray[$need]) * value; } var_dump($conversions); br(); echo converter('USD', 'GBP', 5.25, $conversions); br(); echo converter('GBP', 'CAD', 5.25, $conversions); Try it and let me know how it works.
  16. You'll probably want to add another select box to the left of the condition select box, that will give users the ability to choose from any of the fields in the table. You'll also need to make sure that there are the same number of condition fields, options, and values as part of your validation. ID $_POST['column'] = array( 'columnName1','columnName2','columnName3'); $_POST['operator'] = array( 'operator1', 'operator2', 'operator3'); $_POST['criteria'] = array( 'ccriteria1', 'criteria2', 'criteria3');
  17. To: brady123 There really isn't a need to add a number in the form. The field name is in the input value. Note that your are simply creating an array by having name="column[]". When you post this data again to your script, php combines all the inputs with name "column[]" into an enumerated array. All you are simply trying to do is get the fields for the query. It basically looks like this: $_POST['column'] = array('fieldName1','fieldName2',etc...); Can you explain further what you are trying to accomplish? It sounds like you want to give users the ability to query tables in your db based on conditions that they choose. If this is the case, I think what you have + the code I sent should do the trick. Your flow should be as follows: User chooses tables. Field options are displayed accordingly (to table. IE First Name, Last Name for Customers) User chooses Fields to display (which can vary) User chooses conditions whereby to narrow the query (which can also vary) Form is submitted. At this point, there can be only 1-2 fields that the user wishes to display, with an optional amount of conditions. Therefore, the data I see being key for the submission is: Fields (varies on user selection) Table (based on user selection) Conditions (optional | varies on user selection) Formulate Query. Is this the jist of what you are trying to accomplish?
  18. I think preg_match should do the trick for you. EX: preg_match('/\[(quote) author=([a-zA-Z\'\s]+)]([a-zA-Z0-9\'\t\s\r\n\.]+)\[/quote\]/',$post,$match); <div class="{$match[1]}"><div class="quoteTitle">author={$match[2]}</div> <div class="{$match[1]}"><div class="quoteWords">{match[3]}</div> You'll have to encapsulate $match[1] etc accordingly. Note that the parenthesis in the regex mark subpatterns. btw. Let me know how many bugs are in my code
  19. The issue isn't with re-declaration. I have a main file that includes the page content. Inside the individual page is where I declare this page - specific function. I simply don't want to see fund pred every time I start to type a function in my project IE preg_match. Maybe I'm just being picky, but check out the following tips I've uncovered on my quest to learn how to do this: ctrl + hover on any constant, class, method, function to see documentation click on it and you will be directed to the line of declaration, definition, or instantiation. ctrl + p on parameters to see full list for that function.
  20. Cool idea bro! Give this a shot. It should do what you want, as well as output a query that you can execute. if(!isset($_POST['submit'])) { echo " <form method='post'> <table> <tr> <td valign='top'>SELECT</td> <td valign='top'> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='fields[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> </tr>"; } echo " </table> </td> <td valign='top'>FROM allocations</td> <td valign='top'>WHERE</td> <td> <table>"; // LIST ALL COLUMNS IN A TABLE $result = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $rowcount=mysql_num_rows($result); $y=mysql_num_fields($result); for ($x=0; $x<$y; $x++) { echo " <tr> <td> <input type='checkbox' name='column[]' value='".mysql_field_name($result, $x)."'>".mysql_field_name($result, $x)." </td> <td> <select name='operator[]'> <option value='='>equals</option> <option value='<>'>does not equal</option> <option value='>'>greater than</option> <option value='<'>less than</option> <option value='>='>greater than or equal to</option> <option value='<='>less than or equal to</option> <option value='LIKE'>is like</option> </select> </td> <td><input type='text' name='criteria[]'></td> </tr>"; } echo " </table> </td> <td valign='top'><input type='submit' value='Process Query' name='submit' class='submit'></td> </tr> </table> </form>"; } else { $fields = ''; function build_fields(&$field, $name) { $field .= $name; } $conditions = ''; function build_conditions(&$condition, $where, $opt, $value) { $condition .= "$where $opt '$value'"; } $numFields = count($_POST['fields']); for ($i=0; $i <= $numFields; $i++) { $x = ($i == $numFields ? null : ', '); build_fields( $fields, $_POST['fields'][$i].$x ); } echo "<b>Fields to edit:</b> ".$fields; echo "<br><br>"; $numColumns = count($_POST['columns']); for ($i=0; $i <= $numColumns; $i++) { $x = ($i == $numFields ? null : ' and '); build_conditions( $conditions, $_POST['column'][$i], $_POST['operator'][$i], $_POST['criteria'][$i].$x ); } echo "<b>Columns to query:</b> ".$conditions; echo "<br/><b>Query to Execute (optional)</b><br/> SELECT $fields WHERE $conditions"; }
  21. Hi all, I have a function that is only used in the file it is declared in : /index.php /** * This function is used to display form messages. * * @param string $msg This explains login and session status . * * @access private * * @return string */ function pred($msg) { return "<p class='content' style='color:red;'> $msg</p>"; } I'm using netbeans 7.0 (which by the way rocks !!!!! ), and I don't want to be able to see the documentation in other files when I start typing something similar. I read at pear.net coding standards that the '@param private' can be used on class methods. Is there a way to make the documentation private to the file that the function is declared in? I'm simply trying not to flood other files in the project with needless function suggestions. Thanks in advance.
  22. Thanks for the advice. I'm assuming that your are referring to php5 best practices by using public static? Is this mainly for code readability? I'm juggling between my hosting which uses php4 and zend php cert. 5.3 that I'm studying for.
  23. OK, so I'm trying to create a central db class for data validation, etc. I'm starting off with the data. this code works for me, I just want to be sure that I'm not missing anything. Will dbData be accessible globally? class dbData{ function regex_key_data($reg){ $z = '/[a-z\s\'{1}]*/'; $d= array( 'domain'=>'/^[a-z0-9-.]+\.[a-z0-9]{2,4}$/i', 'email'=>'/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]+$/i', 'GUID'=>'/[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}/', 'html'=>'*htmlentities', 'int'=>'[0-9]', 'string'=>'*mysql_real_escape_string', 'fname'=>$z, 'lname'=>$z ); return $d[$reg]; } function test($reg,$val){ $z = preg_match(dbData::regex_key_data($reg),$val ,$dom); return ($z?$dom[0]:false); } } function clean_it($v,$type = 'none'){ $v = urldecode($v); if(!empty($v)){ switch($type){ case 'domain': return dbData::test('domain',$v); break; case 'email': preg_match('/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]+$/i', $v,$email); if(empty($email[0])){return 'empty';} else{return mysql_real_escape_string($email[0]);} break; case 'GUID': return mysql_real_escape_string($v); break; case 'html': return mysql_real_escape_string(htmlentities($v)); break; case 'int': if(is_numeric($v)){return $v;} break; case 'string': return mysql_real_escape_string($v); break; } } else{ switch($type){ case 'domain': case 'none': case 'string': case 'email': case 'GUID': case 'html': return 'empty'; break; case 'int': return 0; break; } } } $br = '<br/>'; echo dbData::test('GUID','ASDFASDF-ASDF-ASDF-ASDF-ASDFASDFASDF').$br; echo dbData::test('email','asdf@asdf.asd').$br; echo clean_it('asdfsdf.com','domain');
×
×
  • 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.