Jump to content

hansford

Members
  • Posts

    562
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by hansford

  1. Form this into another question and post another topic so you can benefit from other members' input on the forum. Many, way more knowledgeable than myself.
  2. My two cents: $countries[$Ctry_info['CID'] = $Ctry_info['Country']]; What is this - trying to assign a row value into another row value and putting it in the $countries array. If you're trying to get the country name and then the country id and assign them each to the same array, then try this: $countries[] = array($Ctry_info['CID'], $Ctry_info['Country']); buildSelectOptions( $countries ); function buildSelectOptions($options) { $optionsHTML = "<select name=\"countries\">\r\n"; foreach($options as $c) { $optionsHTML .= "<option value=\"{$c[0]}\">$c[1]</option>\r\n"; } $optionsHTML .= "</select>\r\n"; return $optionsHTML; }
  3. In case you missed it - here's the sign:
  4. Because html is not context free grammar - it's currently forgiving, allowing you to omit closing tags, use wrong nested tags etc. To successfully parse something you need something that is strictly defined. I've used regex to extract data from html and it can be a real pain - especially if the exact layout of the page is not known - your regex will fail and you'll have to add another expression to cover if the page is laid out this way or another way or even another way.
  5. You are going to have to create a cron job for that - a scheduled task on the server. I don't have time to go over it right now, but maybe others will chime in - or you can look up how to do that. You will need to modify your script - possibly have to add a bash command up top. You can set it up to email you when the task is complete.
  6. You should be looking in Html parsing. Here's a link to get you started. http://htmlparsing.com/php.html
  7. Pile, what is your major malfunction! I posted the answer - how many answers do you need for the same simpleton question. Sorry, it's Sunday, so had a couple
  8. This is probably a WHERE clause in a query and the $_POST variables have been directly injected into the query. Never do it - not even in the safety of your own local machine because it just fosters bad programming techniques, fellow programmers will yell at you, girls won't feel secure with you etc.. The PHP Manual is your friend - use it. http://php.net/manual/en/mysqli.quickstart.prepared-statements.php I'm sure DreamWeaver makes things easier, but forget "easy" until you first understand why you should be doing something in a certain way. Don't let the tool make you the tool. (don't allow the applications you use to speed development be smarter than you are)
  9. For the Ajax calls and other JavaScript - I recommend using a library like jQuery for the simple fact that the code has cross-browser support and is routinely updated. No need to check if IE is still an a-hole - who cares.
  10. Doesn't matter. When they log in you start a session and create a session variable to hold their name. <?php session_start(); // checked their log-in credentials in the db - they are authentic // grab their data while you're at it $_SESSION['username'] = $row['firstname'] . $row['lastname'];
  11. I can't speak for the way Shopify specifically achieves this, but this can easily be achieved through Ajax calls to the database. Basically, the user selects certain preferences for background colors etc. and these values are then stored in the db. When the user logs in again, these values are extracted from the db and presented as CSS values. When the user wants to change these settings they have some user settings link which allows them to do this. The information is sent to the back-end through Ajax, stored in the database and then Javascript updates whatever elements on the screen.
  12. If you want their name to appear in the url then just show it regardless whether anyone else has that name. I assume they are logged in so they are the only ones viewing it. The session is what will keep track of who they really are as they move about from page to page. The username is their unique identity, not their real name.
  13. Absolutely. An id wouldn't be much good if it wasn't unique within the database. If two concurrent processes attempt to create the same id - one of them will succeed the race condition and the other will fail with an error.
  14. The selection in the options element should have the id_item as it's value. <select name="whatever"> <option value="123">Girls</option> <option value="456">Women</option> <option value="789">Neither</option> </select> Then in your PHP code: if (isset($_POST['whatever'])) { $item_id = $_POST['whatever']; } The html for the select doesn't have to be hard-coded with those values either. <html> <body> <h1>Welcome to the girls gone lunatic, but we still love them, website!</h1> <?php // connect to your database and grab all of the item_id's // call a function that creates the select element with those values // or just do it the hard way and echo it out... echo '<select name="whatever">'; echo '<option value="' . $row['item_id'] . '">Girls</option>'; // etc.. echo '</select>'; ?> </body> </html>
  15. <?php // make db connection $id = ''; while ( true ) { $id = uniqid(true); $query = "SELECT COUNT(*) FROM $table WHERE reg_id=$id"; $stmt->execute($query); if (($stmt->fetchColumn()) == 0) { break; } } // we have a unique id compared to anything in the db
  16. Each user is going to have a unique ID in the database - if that is tagged onto any sequence of random chars - the registration id will be unique. Why do they even need a registration id - a temp registration number attached to a url that is emailed to them I can see, but that will expire and be deleted from the database.
  17. Not sure of what you want exactly, but I used your code. <?php $num_of_ids = 10000; //Number of "ids" to generate. $i = 0; //Loop counter. $n = 0; //"id" number piece. $l = array("AAA","AAB","ABA","BBA","ABB","BBB","BAB","BAA"); //"id" letter piece. $count = 0; while ($i <= $num_of_ids) { $id = $l[$count] . sprintf("%04d", $n); //Create "id". Sprintf pads the number to make it 4 digits. echo $id . "<br>"; //Print out the id. if ($n == 9999) { //Once the number reaches 9999, increase the letter by one and reset number to 0. $n = 0; $count++; if (count($l) == $count) { break; } } $n++; //Letters can be incremented the same as numbers. Adding 1 to "AAA" prints out "AAB". }
  18. I understand you want an item id and you want to send it to the db. Where does this id come from? You have a lot of outdated code going on here. You state the form isn't getting processed - why. Where's the error handling to alert you when values don't exist or something doesn't work as intended. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { Does any code after this get called?
  19. Notion, I've been working on this too since our last post regarding this. password_hash() returns a string. The manual posts this: /** * We just want to hash our password using the current DEFAULT algorithm. * This is presently BCRYPT, and will produce a 60 character result. * * Beware that DEFAULT may change over time, so you would want to prepare * By allowing your storage to expand past 60 characters (255 would be good) */ So I would assume we would need a varchar() or char() capable of holding 255 characters.
  20. I thought the guy was posting spam, so didn't bother to reply. heredoc is my favorite when you need to write line after line of text.
  21. You can use Ajax for this functionality. Once a directory is selected a JavaScript event is triggered that sends the selected value via Ajax to some PHP file on the server. PHP can then query the database for the information required to fill the child drop down and return that information to Ajax. The second drop down is then dynamically filled with the appropriate values.
  22. Now it's perfectly clear and Barand posted exactly what you need. I'll just elaborate since the code is already posted and so you understand how to do it next time. // set a default value of zero to compare against other possible numbers $maxshipping=0; foreach ($_SESSION['products'] as $prod) { // compare each number in the array and assign the highest value to $maxshipping $maxshipping = max($maxshipping, $prod['shipping1']); } echo $maxshipping;
  23. namespace NamespaceA { class A extends \NamespaceB\B { function __construct() { echo "class A<br />"; parent::__construct(); } } } namespace NamespaceC { class C { function __construct() { echo "class C<br />"; } } } namespace NamespaceB { class B extends \NamespaceC\C { function __construct() { echo "class B<br />"; parent::__construct(); } } } I will grant you that it is odd behavior. However, namespaces were designed to be located each in their own file. That's my story and I'm sticking to it!
  24. It seems we are stuck on the $_SESSION['products'] array. Before we loop through and this and that, let's just see what the array actually contains. echo '<pre>'; print_r($_SESSION['products']); echo '</pre>';
  25. Thanks Jacques. I actually counted on your critique so I could update this old code. I'll open a new thread once I write some new code and allow you guys to chip away the cracks.
×
×
  • 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.