Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. Hey Barand, Seems from the post there are no rows, so you only have to deal with gaps. @jiros1: Seems like these are your requirements: I can't think of any specific array functions that will help you with this other than array_merge for building the initial master seating array from the list of reserved seats and the entire theater. What does occur to me is that a data structure that stores seat openings from first to last might be helpful. If you generated something like this: $gaps[] = array('start' => 1, 'end' => 4, 'count' => 4); Then you could traverse that looking for blocks of seats that are >= the size you need. Obviously your function would need to traverse the master array once it's loaded with reservations and generate the $gaps array.
  2. Hi, Since Pusher isn't an option for you, here is an option to look at that will allow you to keep your server side codebase in PHP: http://socketo.me They have a simple proof of concept/tutorial. I'd recommend following those steps and get everything installed and tested, and from there it would just be a matter of adding your specific application logic.
  3. Yes you can enclose whatever you want in a transaction. That is the point of them -- and they are of course not limited to one table. You could insert in table A, Delete from Table B, and update table C, all inside one transaction. The important thing to know is that with mysql your tables need to be of an engine type that supports transactions. Most people have traditionally used Innodb engine tables for this requirement.
  4. I would think that being Deaf would primarily cause concern in regards to how employers will be able to communicate with you, and this could influence the way they think of you as a potential employee. The actual process of developing wouldn't be an issue. I think that unfortunately, you might have to work a bit harder at having a portfolio and possibly some github sourced code, or other things that you can use to show people you are competent and capable. You want to create some working sites that show what you are capable of.
  5. Web sockets is the evolution of ajax requests (and Long Polling), and has features that improve on things in ajax that are not ideal for persistent connections. There are useful things available in Websockets that support pub/sub which for something like a user list is really nice. In all cases the client side technology is javascript. On the server side, there are various ways to implement a web socket server, although web sockets have largely grown up along with Node.js and frequently people who roll their own solution do so with Node. A way around the entire requirement for a separate web socket server process is to use Pusher, which acts as a proxy for you. It accepts the web socket connections on your behalf from your clients and makes calls to your server to get the actual information needed to service the connection. They have lots of code example and it's not a bad idea to try them out to get your feet wet with web sockets.
  6. The modern way of doing this stuff is websockets. I would look into that. There are also SaaS web sockets server support from companies like https://pusher.com I've used Pusher in the past successfully, although there are others now you might investigate.
  7. Well that's actually the issue that Zephni stumbled upon. Whether or not you specify it as a string, PHP will convert it to it's numeric equivalent. This was done to avoid the possible confusion of people trying this: $a = array(0 => 'numeric_zero', "0" => 'string_zero'); What happens in this case, is that whatever is declared last ends up in the array: array(1) { [0]=> string(11) "string_zero" } PHP is trying to save people from themselves, I suppose.
  8. I agree with Jacques that there is probably a better way, however given the limited info provide, it seems that you just need to know whether an array is flat or multi-dimensional. The problem is that for php, there is no difference between the 2 arrays you show. In your example, you are defining them differently, but the end result is the same: $a = array("item1", "item2"); $b = array("0" => "item1", "1" => "item2"); var_dump($a); var_dump($b); You'll get this result: array(2) { [0]=> string(5) "item1" [1]=> string(5) "item2" } array(2) { [0]=> string(5) "item1" [1]=> string(5) "item2" } Again I'm not sure if this is helpful to you, but when you don't specifically indicate the array key for a flat array, it will be zero based. When you do specify an array key of any type, that will be honored by php. So if you started your other arrays at "1" you could then tell the difference between each type on the basis of whether or not a zero-th element exists or not. See this: $a = array("item1", "item2"); $b = array("1" => "item1", "2" => "item2"); var_dump($a); var_dump($b); function hasZeroElement($array) { return isset($array[0]); } if (hasZeroElement($a)) { echo "A has zero index"; } else { echo "A has NO zero index"; } echo "\n"; if (hasZeroElement($b)) { echo "B has a zero index"; } else { echo "B has NO zero index"; } echo "\n"; Result!: array(2) { [0]=> string(5) "item1" [1]=> string(5) "item2" } array(2) { [1]=> string(5) "item1" [2]=> string(5) "item2" } A has zero index B has NO zero index
  9. DKIM and SPF are for entire organizations. Unless you were hosting all mail activities for a domain, or acting as a forwarding agent, you wouldn't be interested in those technologies. In other words, you can't for example, change the SPF information for each outbound email. BigCo.com would have to set up an SPF entry in their DNS that would indicate that your mail system was authorized by them to send email on their behalf. That is not going to happen. DKIM is a similar and even more strict technology that uses public/private key setups in the MTA (mail servers) to sign emails so that other servers can verify that they actually came from your domain. Again this would not be applicable, but these features of email security were brought up because we needed to clarify what you are doing. It seems at this point, we all agree that the solution you want is stated by you in your most recent responses: 1. Send the email From: account@yourdomain.tld 2. Add the reply to: original username You could experiment with setting the "text name" portion to be the same for both, as it just occurred to me: Some Name <email@domain.tld> From an end user standpoint this is much better to send the mail with the descriptive name that you're presumably getting from the users, and as this is coming from a form they fill in, you can do some checking there to make sure you have a semi-valid name, or don't allow the form to send the email, which will knock down some bots, or at least make the emails they send less likely to confuse the end users. You want to take whatever precautions you can on this type of form to make it hard for a bot to utilize it to spam a lot of people.
  10. So if I understand you, you have a "classType" list? classType ------------ 1. ASL1 2. ASL2 3. ASL3 etc. But you also describe this as being the "class" and not a type at all. What it sounds like is that this is a classic students/classes/grades system? The tables you want in that case are typically something like this: +--------------------+ | Student | +--------------------+ | student_id (pk) +------+ | | | +-------------------------+ +--------------------+ | | ClassStudent | | +-------------------------+ | | classStudent_id (pk) | | | +--------------------+ +----> + student_id (fk) | | Class | | | +--------------------+ | | | class_id (pk) +-----------> | class_id (fk) | +--------------------+ | | | year | | semester | | grade | +-------------------------+
  11. In my queries I screwed up looking at the tables, and should have removed the references to m.status = 1, and had 2 criteria in the other ON clause: LEFT JOIN teams_info as ti ON (ti.team_id = tp.team_id AND ti.entry_year = 2015 AND ti.status = 1) As I mentioned, there are frequently different ways to do the same thing, and Barand actually tested things out for you, where I didn't, but he shows the option of using the WHERE clause for filtration.
  12. Exactly. As I said above, when you move the functions around it makes it clearer that you have logic holes in what you were doing. I didn't fix your code, just ordered it so that it wasn't so confusing and you could see clearly what you had.
  13. Basically I agree with ginerjm's summary of my comments. Is this a generic feature of your site, or do you have some special relationship with bigcorporation.com that we're unclear on? With the header you provided there are some interesting things it is telling you. One is that bigcorporation.com doesn't have an SPF entry in their DNS, so google is not marking you down for that. Not having SPF is unusual these days. With that said, gmail doesn't provide you insight into how they determine things to be spam. They just stick stuff in spam using whatever internal criteria they choose. Other businesses may be using spam assassin or some other system that will frequently add custom mail headers with scoring information that many clients use. At the end of the day, unless you have a special relationship, and have had sysadmin cooperation taking place behind the scenes so that you are a valid MTA for the domain or have added an SPF or DKIM for that business into your MTA, then you're going to have issues. It looks like you are using the smtp1.mywebhosting.com MTA to send your emails out, so this certainly qualifies as "spoofing" and I guarantee you that your email is going to be considered spam by many systems. Just because you are receiving it on a test account within gmail doesn't mean that many other accounts even within gmail will have it considered spam. The large hosted email providers like yahoo, google and microsoft have complicated proprietary systems that do all sorts of processing to make individualized determinations about what they classify as spam on a user by user basis. If your box has previously received a lot of email from mywebhosting.com, for example, they may be de facto whitelisting other emails, when for some other user, they would stick it in the spam folder.
  14. Here's the group by example, just for reference: SELECT m.gender, m.count(*) as countOf FROM team_players as tp LEFT JOIN teams_info as ti ON (ti.team_id = tp.team_id AND ti.entry_year = 2015) LEFT JOIN members as m ON (m.members_id = tp.members_id) GROUP BY m.gender
  15. Make sure you read Barand's great post before you jump right into cribbing from my SQL statements!
  16. Are you using mysql or some other RDBMS? I'll assume mysql here, as there are a variety of join syntaxes you can use and they vary by database. What you want to do here is do an INNER join of all 3 tables which will give you one row per intersection. Fortunately, you have a good basic normalized structure that has separated the TEAM entity from the MEMBERS (players). Because your app supports "seasons" you have a good many-to-many resolver table in team_players. So, to join the tables together, strictly speaking it doesn't really matter which table you start with, but in a case like this, I will start with the many to many resolution table: SELECT * FROM team_players as tp LEFT JOIN teams_info as ti ON (ti.team_id = tp.team_id) LEFT JOIN members as m ON (m.members_id = tp.members_id) At this point, you are inner joining and should have 1 row essentially for every match, which is going to be one row for every row in team_players. In your examples, you want a count, so rather than SELECT *, you just want COUNT(*) as 'some_name'. What you alias that name to be is up to you. For example you could have: SELECT count(*) as accepted_in_2015 FROM team_players as tp LEFT JOIN teams_info as ti ON (ti.team_id = tp.team_id) LEFT JOIN members as m ON (m.members_id = tp.members_id) Of course, what is missing now is the filtration. You can add these with a WHERE clause in most cases, but I typically add them in the appropriate join criteria. So when I'm adding a WHERE/filtration criteria that has to do with a team, I will put it in the ON that involves the teams_info join. Where it's a 'member' table criteria (status in your first question) I add that there. So to answer your first question, this should probably work:
  17. I'm not sure why you would use 3 columns. If you want to explain what you are trying to do, I can help with the proper database design.
  18. benanamen's main point is probably the issue. Probably your version of php was updated and the mysql_ functions are deprecated and have been removed entirely. You need to either use mysqli_ or pdo, and adjust your code accordingly, but that could be a substantial undertaking, as it should effect your entire code base any place that mysql is being used.
  19. I took your code and did the moving for you. Once you start moving things into sections, the logic issues with your current code start to become more obvious. What's obvious at present is that the html header code needs to be either separated or moved inside a function so that it can be rendered before the form code is rendered OR before the error code is rendered. <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); require_once('functions.php'); function outputErrors($sql_errors) { foreach($sql_errors as $name => $msgs) { echo('<h4 class="error">' . $name . ': ' . $msgs . '</h4>' . PHP_EOL); } } function validateInput() { global $errors; $status = true; if($_POST['fname'] == "") { $errors['fname']="Please enter your first name"; $status = false; } if($_POST['lname'] == "") { $errors['lname']="Please enter your last name"; $status = false; } return $status; } //end user validation function display_form() { global $errors; ?> <form action="stickyForm.php" method="post"> <label> <input id="fname" type="text" name="fname" size="15" placeholder="First Name" value ="<?php if(isset($_POST['fname'])) echo $_POST['fname'];?>" > <input type="text" name="lname" size="20" placeholder="Last Name"><?php echo !empty($error['lname']) ? $error['lname'] : '';?> <input type="text" name="orgName" placeholder="Organization's Name"maxlength="50"> </label><br /> <label> <!--new row --> <input id="address" type="text" name="address" size="15" placeholder="Street Addresss" maxlength="50"> <input id="city" type="text" name="city" placeholder="City" size="10" maxlength="25"> <select id="state" name="state" placeholder="State" value=""> <option value ="">Please choose a state</option> <?php states($state); ?> </select> <input id = "zipcode" type="number" name="zipcode" placeholder="Zip Code" size="5" maxlength="5"> </label><br /> <label> <!--new row --> <input type="text" name="phone" placeholder="Phone Number:(including area code)" size="10" maxlength="10"> <input type="text" name="fax" size="10" placeholder="Fax Number: (including area code)" maxlength="10"> </label><br /> <label> <!--new row--> <input type="text" id = "email" name="email" placeholder="Email Address" /> <input type="text" id = "confirmEmail" name="confirmEmail" placeholder="Confirm Email Address" /> </label><br /> <label> <!--new row --> What would you like help with? <table id="projectOptions"> <tr span=2> <td><input type="checkbox" name="projectOptions[]" id="projectOptions[]" value="socialMedia">Social Media</td> <td><input type="checkbox" name="projectOptions[]" id="projectOptions[]" value="webContent">Web Content Management</td> </tr> <tr> <td><input name="projectOptions[]" type="checkbox" checked="checked" id="projectOptions[]" value="marketingMaterial">Marketing Material Creation</td> <td><input type="checkbox" name="projectOptions[]" id="projectOptions[]" value="seo">SEO (Search Engine Optimization)</td> </tr> <tr> <td><input type="checkbox" name="projectOptions[]" id="projectOptions[]" value="videoEditing"> Video Editing</td> <td><input type="checkbox" name="projectOptions[]" id="projectOptions[]" value="webDesign">Web Design</td> </tr> </table> </label> Overview about the project:<textarea rows="5" cols="10" placeholder="Overview of Project"></textarea><br /> If you are not a robot, what year is it? <input type="text" name="year" size="4" maxlength="4"><br /> <input type="submit" name="submit" value="Contact Me!"> <input type="reset" name="reset" value="Cancel"> </form> <?php } $errors=array(); //validate user's input if(isset($_POST['submit'])) { validateInput(); if(count($errors) != 0) { display_form(); } else { display_form(); } $sql_errors = array(); $mysqli = databaseConnection(); if(!$stmt = $mysqli->prepare("INSERT INTO clients(fname, lname, orgName, address, city, state, zipcode, phone, fax, email, confirmEmail, projectOptions, projectOverview, year) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $sql_errors["Prepare"] = $mysqli->error . PHP_EOL; } else { if(!$stmt->bind_param('ssssssiiissisi', $_POST["fname"], $_POST["lname"], $_POST["orgName"], $_POST["address"], $_POST["city"], $_POST["state"], $_POST["zipcode"], $_POST["phone"], $_POST["fax"], $_POST["email"], $_POST["confirmEmail"], $_POST["projectOptions"], $_POST["projectOverview"], $_POST["year"])) { $sql_errors["bind_param"] = $stmt->error . PHP_EOL; } else { if(!$stmt->execute()) { $sql_errors["execute"] = $stmt->error . PHP_EOL; } $stmt->close(); } } $mysqli->close(); header('contactTest.php'); } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style type="text/css"> .error { color: #FF0000; } </style> </head> <body> <?php if(isset($sql_errors) && sizeof($sql_errors) > 0) outputErrors($sql_errors); ?> </body> </html>
  20. Yeah, I dislike the enum type myself. First off, it's not standard SQL, so it's only supported in a handful of DB's. I think you should have a really good reason to use an rdbms specific implementation. Secondly and much more importantly, you are mixing DDL/schema definition with "data". The decode values for the internal enum representation can just as easily be done as a separate table with a foreign key relationship, and you at that point don't need to allow updating the actual table definition in order to add or delete from the enum list. I find that people are of one of 2 minds: 1. I want everything relational, and configurable through the db. If that's the case then use a separate "lookup" table and relate it using the foreign key. You can minimize the storage cost in mysql by going as granular as a char(1) or a tinyint. You also have the benefit of using foreign key constraints for data integrity, while still allowing an admin system to add new values. 2. I want my code to drive this, so that I can reduce load on the db. Often people will have a list of constants, perhaps in an array: $shirtsize = array('s' => 'small', 'm' => 'medium' 'l' => 'large' 'x' => 'extra large' ); This is all an enum is doing for you, and if your argument is that you don't want to pay the price of having an actual legitimate relation by foreign key, then this is often better represented in the server side code, where you can then do things like string localization, and where the enum doesn't benefit you. It seems like your question is in regards to how you update the list of allowable values for the enum, and the answer is -- you have to alter the table. As I said originally, you don't want to do that, because you really don't want your application to even have the rights to do DDL calls that can add tables, drop tables or alter their structure. A glitch or an exploit and your whole database can easily be zapped by an attacker. Also altering a table requires it to be locked which limits concurrency and uptime for your app. If I'm not understanding your question correctly please elaborate, but my advise would be to avoid using enums, since you have several simple and standard options that allow you to do what you need to without them.
  21. First I'd suggest moving your function display_form() { .... } code to the top of the script right after your other function declaration and before your actual script logic code. Re-run ad check your error logs and see what they are telling you.
  22. Hi NotionCommotion, Just to clarify what you are doing, albeit for ostensibly understandable reasons, is one or both of "spoofing" or "relaying" which are considered highly undesirable by spam classification systems. They also, depending on the implementation, open your site up to blacklisting, because nefarious individuals often exploit these features, which used to be common but are now considered a "really bad idea" to send spam, using your systems. So first relaying: When you are the Mail transfer agent (MTA) for a domain or even several domains, that is something that is configured in DNS, in your MTA settings, and typically has SPF and DKIM settings wired in. These are things the sysadmin configures, and there are also reverse DNS settings that come into play. In summary, the only emails your MTA is supposed to send on your behalf are emails from user@yourdomain.xyz. If your MTA sends out emails or relays emails from user@someotherdomain.com, then you are "relaying" emails for that domain, and that is not supposed to be possible, and is an exploitable problem that degrades email for everyone. That will get you on blacklists. I'm not sure how you are sending out emails, as it is possible to send them directly from an app server, but that is also a great way NOT to get your emails delivered. Sure they will go out and even be received by some sites, but many more will blackhole your emails (receive and silently delete them) or grade them with high spam scores that are sent to the end user's spam box. You can also again, get your site on blacklists for doing this. You should only send email out via a valid MTA for your domain! Many sites also, often by necessity use remailing services, especially if they are hosted on cloud services, as many of these services (AWS for example) severely limit the number of emails that can be sent out of their network directly via SMTP protocol. The one trick that people often try and use to get around the problem without entirely violating the rules and spoofing the from address, is to send emails out as a valid user for your domain, but add the "from user" as the reply to email header. I know that's not what you're trying to do, but is about all you are typically allowed to do without raising your spam score to the "this is spam" level of most classification systems. I know this is not what you wanted to do, but you simply can not spoof a from address and send it out of your domain and not suffer repercussions that will at very least have the majority of your emails going into the receivers spam box, or more often than not, simply rejected or silently deleted. This is because spoofing from addresses is harmful to the email ecosystem at large, and is a huge red flag for spam classification systems. It can also cause the receiver's system to erroneously spray error replies to domains that had nothing to do with the email, not to mention the fact, that inherently you are not able to prove to anyone that the email address you are claiming the email is coming from, is actually the person who owns the email in question. This is one reason why the good old html mail tag causes the browser to invoke the user's configured mail client, so that they can send emails out through their own system as it is the only way to legitimately do what you're hoping to accomplish, and have it taken seriously by the receiving email systems. Sorry to be the bearer of the bad news, but the bad people ruined email for the rest of the world a long time ago.
  23. No, sure isn't. Keep in mind you can always use the php.net site. It supports a rewrite for every function via http://php.net/function_name. So for example: http://php.net/date_format Worth trying when in doubt.
  24. Do you have code that generates the gif(s)? That would be the first step I would think. You'd have to clarify what you're trying to do. If it's a wall spamming app, that's not possible anymore afaik.
  25. ^^^^ Seems pretty clear that there isn't a display_form() function defined anywhere that this script has access to call.
×
×
  • 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.