-
Posts
1,698 -
Joined
-
Last visited
-
Days Won
53
Everything posted by maxxd
-
So, apparently it was a combination of operating system and a password-protected directory on the server. On Mavericks (I think, I'm a Window's guy in an Mac world at work), Safari would send the permission request a second time, but would only notify the user of the send under certain circumstances that I still don't know or understand. El Capitan, on the other hand, handled everything fine. I dropped the password protection on the server directory and everything worked as expected in Safari on Mavericks as well, so I'm calling that good enough. Just in case someone else hasn't updated and runs into the same issue.
-
Hey y'all. Not entirely sure this is the correct place for this, but it seemed more appropriate than the Miscellaneous section - feel free to move it if I'm in the wrong spot. I don't do a whole lot of work with video on sites, but a site that I'm working on has a header video. Groovy, right? Nope. I'm using BigVideo.js, and have uploaded .mp4, .mov, and .WebM versions of the file (in that order) to the server. Everything works perfectly in Edge, Internet Explorer, Opera, Chrome, Firefox, and (believe it or not) Safari v5 on Windows 10. Works great in Opera, Chrome, and Firefox on MacOS X. However, Chrome on iPod and Safari on both the iPod and the Mac won't load the video. I get an error to console reading "The video could not be loaded, either because the server or network failed or because the format is not supported." I can post the code here if anyone thinks it'd help, but it's really just instantiate the BigVideo object, then pass the three paths to the videos to it, and it works in every other browser I've tested (italics for frustration, not emphasis so much...). Anyone have any ideas at all?
-
You would use explode() and implode() in an autoloader to use the class's namespace to map a directory structure. For instance, you would map Foo\Objects\MyObject to /Foo/Objects/MyObject.php by exploding on '\' and imploding with '/'. You're getting the 'class not found' error because you're not loading the file that contains the class definition for ooo(). You're not going to add more products to the product class - each instance of the class represents a single product. So, you would have a Shop class that would contain an array of Product classes. (I'm assuming this is from Zandstra's book, as your other post references the book and I remember him using Willa Cather as an example.) I can't remember exactly how he describes using the Product class, but I think he discusses this a bit further on.
-
Barand - absolutely, but if using CSS to modify the display is appropriate and allowed for the assignment, it's another viable way to do it.
-
Not even looking at the code, your setup is seriously flawed. If you're storing the password in the database as plaintext, stop doing that. The password should be hashed before storing in the database, which means you couldn't e-mail the user's current password to them. I mean, you could, but they'd have to decrypt it before they could use it to log in. That's the point - if your database is compromised, the hackers won't have access to plaintext passwords. As for the actual error message you're receiving, you've got a syntax error in your SQL.
-
You can also do this via CSS with text_transform: uppercase.
-
You use add_shortcode() in your functions file, then create the function that will process the and include the image. Depending on how you're trying to get the image, you may also have to look into get_attachment_thumb_url().
-
What results are you trying to get exactly? You talk about needing rows, but you use a DISTINCT clause - which, of course, can return more than one row in the result set - but you also say you need a single result. And then, fetching a column is the answer? What does the query you're running look like, and what is the desired outcome? Just trying to get at the actual issue at hand... That having been said, if you're just looking to grab all the values of a specific column, have you tried PDO::fetchColumn()? Depending on your actual needs, could be the answer.
-
If you want #wrapper to stay the same height, but #custom_content to expand the height of the page as content is entered, take #custom_content out of #wrapper and put a float: none; on both. Change 'height' to 'min-height' in the CSS for #middle. Put the background image on the body itself and set it to position: fixed, and that should do it (assuming I'm understanding the question correctly).
-
Check difference between numeric string and number
maxxd replied to Zephni's topic in PHP Coding Help
I realized that about a second after I hit post. Was still thinking $array['key1'] = "blah" vs. $array['1'] = "blah" instead of $array['1'] = "blah" vs $array[1] = "blah". I was kinda hoping no-one had noticed before I got the chance to remove the evidence... -
Check difference between numeric string and number
maxxd replied to Zephni's topic in PHP Coding Help
Didn't think that reply through - sorry. Move along, nothing to see here... -
The buildSelectOptions() function will create a full, well-formed HTML select element. That element needs to be inside form tags with an appropriate method attribute. Then, the script that will receive the form data (specified by the form's action attribute) will use the form's method (the code from #37, post) to get the values. So, in VerseQuery.php, you can get mood like so: $mood = $_POST['mood']; Now, $mood will be the value selected by the user.
-
You're calling buildSelectOptions() with the second $conn - are you sure that it still contains the desired database connection? As Barand pointed out, you're including 2 separate connection files and overwriting the value of $conn with each. So, at first, $conn is the results of get_db_conn_verse(), then - right before the calls to buildSelectOptions() - the results of get_db_conn_Menu().
-
Why not just use a DateTime object and save the additional hassle? $dt = '2015-09-08'; $dateObj = new DateTime($dt); print("<p>".$dateObj->format('Y-m-d')."</p>"); print("<p>".$dateObj->format('M j, Y')."</p>");
-
I'm assuming that the user has selected an event and mood, and that it was passed from the previous form. At first, I thought your form action was 'get', but it later appeared as though it was 'post'. If you're pulling a default from the database, use the database results to compare against the current option value. If the defaults are a hard-coded value, use those in place of the $_GET/$_POST variables, like this: <!-- Start of FORM --> <form action="VerseQuery.php" method="post"> <?php echo buildSelectOptions('event', getEvents($conn), 1); echo buildSelectOptions('mood', getMoods($conn), 27); ?> <input type="submit" value="submit"/> </form> <!-- End of FORM --> Hope that makes sense this time!
-
No, no, no, nononononononono ... Nope! Beyond what Jaques1 points out, using extract() can easily lead to messy, unreadable code. Where did all those variables come from, and how can you validate the data you're getting if you're not explicitly stating what you expect? extract() is one of a handful of functions I wish was never included in PHP to begin with.
-
The insert statement is good - you're using a prepared statement. Do the same with the select statement. Also, don't use md5() for your password - MD5 has been pretty much obsolete for quite a while now due to the fact that it's not secure. Use password_hash() and password_verify(). Those are a couple things that jumped out at me on a quick look.
-
If you want to do it before the user submits the form, use JavaScript. When a select box is checked, increment a variable. When the user tries to select the fifth checkbox, pop up an alert box and uncheck the last selection. Of course, you'll have to decrement the variable when a select box is deselected.
- 11 replies
-
This could possibly work for you.
-
Limit selection in what way? A little more explanation, please.
- 11 replies
-
I didn't even see that when I was typing up my example...
-
You're still calling buildSelectOptions() from within the <option> tag. The function returns a full select element. You're also submitting the form via $_POST but using $_GET to get the values, and the select names don't match the variables you're trying to use. On top of that, your HTML is malformed. Replace your top form (lines 94 - 104) with this: <!-- Start of FORM --> <form action="VerseQuery.php" method="post"> <?php echo buildSelectOptions('event', getEvents($conn), $_POST['event'],1); echo buildSelectOptions('mood', getMoods($conn), $_POST['mood'], 27); ?> <input type="submit" value="submit"/> </form> <!-- End of FORM --> As for the getEvents() and getMoods() not returning any data, is your database set up in the way described in the query? Table Event_Sub does have an id and Event_Sub_Type, and table Events does have columns id and Event_Type?
-
@Barand - thanks; I forgot to update the function definitions - my bad. @rocky48 - the 'event' and 'mood' string values are assigned to the function parameter $name, and are used in the 'name' and 'id' attributes of the select element only. They don't have anything to do with gathering your data - you could use 'bob' and 'jenny' and it wouldn't matter to the buildSelectOptions() function. The getMoods() and getEvents() functions gather your data from the database and return it as an array. Are you still calling the functions from within an <option> tag in the HTML? Is there a $_GET['mood'] and $_GET['event'] value to pass to buildSelectOptions()? I'm assuming you've turned on error reporting as you're getting errors... What does the code look like at this point?
-
You had the same problem earlier ( post #8 ), and you still haven't fixed it as I suggested ( post #9 ). Also, the code you are using now is calling the buildOptions() functions from within an <option> tag in the HTML. The output of this method is a full <select> element, with options. You can't simply copy and paste example code - you have to read it, think about it a little bit, and then implement it in a way that makes sense in the context of your project.
-
Perhaps an annotated version will help. /** * Builds an HTML <select> element with options. * Will mark an option selected if passed a target value and that value is in the * array of options. * * Usage examples: * To print an Events select where the best event ever is already selected: * echo buildSelectOptions( * 'event', //name of the select element - arbitrary and totally up to you * array( * 1=>'Gala', * 2=>'Birthday Party', * 3=>'Wine Night' * ), //the data from which the user can select * 3 //the desired event option to be selected * ); * * To print a Moods select asking the user to select an event: * echo buildSelectOptions( * 'mood', //name of the select element - arbitrary and totally up to you * array( * 1=>'Meh', * 2=>'Blerg', * 3=>'Woot!' * ), //the data from which the user can select * //note nothing is passed here - this is fine because $current is optional * ); * * @param string $name DOM element name and id * @param array $options Options to display in the drop-down for the user to select * @param int|string $current Optional currently selected value. This can come from user * input, a database query, or can be a hard-coded default value. * @return string The full HTML string defining the <select> element and it's associated <option> values. */ function buildSelectOptions($name, array $options, $current=null){ $htmlString = "<select name='{$name}' id='{$name}'>\n"; $htmlString .= "\t<option value='-1'> -- Please select -- </option>\n"; foreach($options as $value=>$option){ $htmlString .= "\t<option value='{$value}'"; if($value == $current){ $htmlString .= " selected"; } $htmlString .= ">{$option}</option>\n"; } $htmlString .= "</select>\n"; return $htmlString; } /** * Gather and return the data in table 'Events'. * @return array An associative array of Events and their ID's as such: * $ret[event id] = event type */ function getEvents(){ $qry = "SELECT id ,Event_Type FROM Events ORDER BY id"; $sql = mysqli_query($conn, $qry); if(mysqli_num_rows($sql) < 1){ return array(); } while($res = mysqli_fetch_array($sql)){ $ret[$res['id']] = $res['Event_Type']; } return $ret; } /** * Gather and return the data in table 'Moods'. * @return array An associative array of event sub types and their ID's as such: * $ret[mood id] = event sub type */ function getMoods(){ $qry = "SELECT id ,Event_Sub_Type FROM Moods ORDER BY id"; $sql = mysqli_query($conn, $qry); if(mysqli_num_rows($sql) < 1){ return array(); } while($res = mysqli_fetch_array($sql)){ $ret[$res['id']] = $res['Event_Sub_Type']; } return $ret; } /** * Print the select elements to screen. */ echo buildSelectOptions('event', getEvents(), 3); echo buildSelectOptions('mood', getMoods()); Using the examples in the documentation, you will see the following output on your page: <select name='event' id='event'> <option value='-1'>-- Please select --</option> <option value='1'>Gala</option> <option value='2'>Birthday Party</option> <option value='3' selected>Wine Night</option> </select> <select name='mood' id='mood'> <option value='-1'>-- Please select --</option> <option value='1'>Meh</option> <option value='2'>Blerg</option> <option value='3'>Woot!</option> </select> Please note that this script is assuming the user has submitted a form where the option 'Wine Night' is the selected event and 'Woot!' is the selected mood upon page load. When the form is submitted, if it's redrawn, you would use the user input as the currently selected value (either $_POST['event'] or $_GET['event'] and either $_POST['mood'] or $_GET['mood'], depending on the form's action attribute).