Jump to content

SF23103

Members
  • Posts

    100
  • Joined

  • Last visited

Everything posted by SF23103

  1. Thank you for your help, It is a little strange, I know. The client wants people to be able to reserve one of two times on one date. Instead of the obvious: having a max number of reservations for each of the two times, they want to max it out by number of the total reservations for that day. Doesn't make sense to me, but that's what they want. I guess what I should be doing, is querying the database for the dates, but ignoring the times? I also forgot to mention that the Reservations table has a column for the number of people in the party for that reservation. I like the idea of joining based on the date ID's, not the actual dates.. that may make it easier. I'll play around with that.
  2. I am looking for a little help on the direction to go with the logic for a MySQL query. I'm not looking for someone to program it, just point me in the right direction for the logic. 1) I have a table that contains available reservation dates. It is populated with several dates. There are two reservation times per day, 12:00 and 12:30. Dates are in date format and stored correctly, but listed below as text for example. See Table 1 below. 2) I have another table that contains reservations. This is populated when someone completes a form for the registration. Dates are stored in the same correct date format, but listed as text below. See Table 2 Below I would like to query the database and Loop through a list of all available dates/times. There are 80 reservations per day, and the times do not matter. For example, "The SUM of January 1, 2017 12:00 AND January 1, 2017 12:30 is less than or equal to 80" would echo both January 1, 2107 12:00 AND January 1, 2017 12:30. I am currently just looping through the list from the dates table based on another column that is "available" or "not available" but that requires someone to go in and modify it manually. I want it to remove the dates automatically when the number of reservations is greater than 80 for that day. -------------------------------------------------------------------------------------------------------------------------------------------------------- Table 1 - Dates (dates are in date format, but just written in text for this example) ID | DATE 1 | January 1, 2017 12:00 2 | Date 2: January 1, 2017 12:30 3 |January 2, 2017 12:00 4 |January 2, 2017 12:30 5 |January 3, 2017 12:00 6 |January 3, 2017 12:30 ... and so on. Table 2 - Reservations (Here, people have made reservations and their reservation is saved in this table). Reservation# | Date ABC123 | January 1, 2017 12:00 ABC456 | January 1, 2017 12:00 ABC667 | January 1, 2017 12:00 ABC777 | January 2, 2017 12:30 etc etc
  3. Thank you for the direction! I've totally scrapped that horrible idea haha. I am now following PRG after the mail is sent if it's successful. I've also combined the mail code in there instead of using an include. Thank you!
  4. I may be going about this all wrong, so hopefully someone can help me out! I have an order form that processes with Braintree. If the transaction is successful, it displays a success message with the order number, and calls a different php file that sends a confirmation email. If the transaction is not successful, it displays error messages. The issue I found was that if the transaction is successful, and the user reloaded the page, it would re-send the confirmation email. This could happen repeatedly. To prevent that, I thought I would add a $order_complete variable. In the original success check, I would check to see if order_complete was "1". If not, display the success text, send the email, and set order_complete to "1". If the page was reloaded and order_complete was "1" it would not re-display the success message and not send the email. Else, it would display the errors. Unfortunately this isn't working. It still sends an email every time! Any suggestions? if (($result->success) && $order_complete != "1") { $_POST['transaction_id'] = $result->transaction->id; echo "<p style=\"color:#000; background-color:#008000; padding:20px;width:70%;\">Your order was successful. Thank you for your support!<br/><br/>"; echo("Your transaction ID is: " . $result->transaction->id . "<br /><a href=\"index.php#go_to_form\"> Click here to order again!</a> </p>"); $order_complete = "1"; include ('/path/to/send_mail.php'); } else if (($result->success) && $order_complete == "1") { echo "Place an Order"; } else { foreach (($result->errors->deepAll()) as $error) { $braintreeError[] = $error->message; } }
  5. I'm using Braintree, but I must be doing something wrong with the unique transaction ID/nonce. In looking at the code, it seems to post the transaction_id after success. if($_POST['month']) { $result = Braintree_Transaction::sale(array( "amount" => $fields[total_cost] . ".00", "creditCard" => array( "number" => $_POST["number"], "cvv" => $_POST["cvv"], "expirationMonth" => $_POST["month"], "expirationYear" => $_POST["year"], "cardholderName" => $_POST['first_name'] . " " . $_POST['last_name'], ), "customer" => array( "firstName" => $_POST['first_name'], "lastName" => $_POST['last_name'], "email" => $_POST["billing_email"], ), 'customFields' => array( "class_name" => $fields[class_drop_down], "token" => $fields[token], ), 'billing' => array( "postalCode" => $_POST["billing_zip"], ), )); if ($result->success) { $_POST['transaction_id'] = $result->transaction->id; $params = array( "submit_button" => "submit", "form_data" => $_POST, "no_sessions_url" => "registration.php", "next_page" => "registration-page4.php", "finalize" => true, ); ft_api_process_form($params); $passing_transaction_identification = ($result->transaction->id); } else { $declined_error = "TRUE"; foreach (($result->errors->deepAll()) as $error) { $braintreeError[] = $error->message; } } }
  6. That makes sense, and I can see how that would prevent refresh and back button resubmission. Does that protect against multiple submit button presses while awaiting the success notification from the payment processor? I think people are pressing submit again during the lag that is occurring while the payment is being processed before they are sent to the thank-you page.
  7. Hello, I have a multi page form. On the third and final page, the user submits payment information. Upon form submission, it sends payment information to a payment processor. If it is successful, the form submits all of the form data to my database. It includes a payment successful field in my database, but of course no credit card information is stored - that's all handled on the payment processor site. If the payment is not successful, the page loads errors to the user and the form is not submitted to my database until the payment is successful. I am starting to see an issue where I am receiving duplicate payments. I am assuming that people are clicking the submit button multiple times while the payment is processing, and it's sending multiple authorization requests to the payment processor. The payment processor automatically catches some of these, but not all. My question is to what logic is most appropriate reduce duplicate payments. The solution that came to mind was disabling the submit button upon click, but then re-activating if the payment was declined, so the user could re-submit. Of course, I would rather solve this on the server side with php. Is this best handled with cookies? If so, can someone explain the basic logic on how that would work? Thanks for your help as always.
  8. Thank you both! Based on both of your suggestions, I went with DateTime objects, and it's working great. That's a good point about error handling.. so I'll work on that next. Also, I see that PHP even has a date_sunset that returns the time of sunset (also one for sunrise) for a given day and location. Pretty cool, maybe I'll play with that too.
  9. Hello, I am getting the sunset and sunrise time through an API that gives the time in these variables: $sunrise_hour , $sunrise_minute $sunset_hour , $sunset_minute I am putting them together to get the time of the sunset and sunrise: $sunset_time_formatted = "$sunset_hour:$sunset_minute PM"; Now, if I need to compare the sunset and sunrise time to the current time, ex: date("h:i A"); do I need to convert the $sunset_time_formatted to UNIX time first? The argument I came up with doesn't seem to work correctly. My guess is it needs to know how to read my sunrise and sunset formatted variables as a real time. if ($current_time > $sunrise_time_formatted && $current_time < $sunset_time_formatted) { echo "sun"; } else { echo "moon"; }
  10. Thank you. Just did some reading on the differences between single, double, and triple ='s. Thanks!
  11. I'm trying to GET from a URL, and IF index.php?preselect=testing THEN $preselect_command = 'this is a command...' Why, no matter what I put in the index.php?preselect='WHATEVER' I always get "this is a command..." to echo? I know I'm missing something! if (isset($_GET['preselect'])) { // Check to see if preselect is set in the url. $preselect = $_GET['preselect']; // if preselect is set, put it to my variable } else { $preselect = NULL; // Fallback to null if it's not set } if ($preselect = 'testing') { // if $preselect equals "testing" then, $preselect_command = some text 'this is a command...'. $preselect_command = 'this is a command...'; } else { echo "something else..."; } echo $preselect_command;
  12. Yes, that's what I'm going for, but on mine for some reason it's doing the border around the text "option 1" and not the entire option1 div.
  13. That puts a border around all three selections. If you check out the JsFiddle, I'm looking to move the dynamic box from around the words to around the whole option box.
  14. Hello, I am having difficulty with this one. I am trying to change the border around the entire div (e.g. #option1) instead of just the text. As you can see, when you click each radio button it changes the border around the option text, but not the entire div. Any suggestions? JSFIDDLE: https://jsfiddle.net/1hdv2n3h/1/ HTML <div id="wine_club_selection"> <div id="option1"> <p><input type="radio" name="club_type" checked="checked" value="option 1"><br/> <span class="bold_text">Option 1</span><br/> 3 Bottles<br/> 15% Discount<br/></p></div> <div id="option2"> <p><input type="radio" name="club_type" value="option 2" ><br /> <span class="bold_text">Option 2</span><br /> 6 Bottles<br /> 20% Discount<br/> </p></div> <div id="option3"> <p><input type="radio" name="club_type" value="option 3"><br> <span class="bold_text">Option 3</span><br /> 12 Bottles<br /> 25% Discount<br /> </p></div> </div> CSS #wine_club_selection { height:200px; width:800px; } #option1 { float:left; width:266px; } #option1 p { text-align:center; } #option2 { float:left; width:266px; } #option2 p { text-align:center; } #option3 { float:right; width:266px; text-align: center; } #option3 p { text-align:center; } .bold_text { font-weight:800; } #option1 input[type="radio"]:checked ~ *{ border: thin solid #F00;!important; } #option2 input[type="radio"]:checked ~ *{ border: thin solid #F00;!important; } #option3 input[type="radio"]:checked ~ *{ border: thin solid #F00;!important; }
  15. Thank you. Sorry, I stopped following the last thread after it was solved. Your explanation as to not maintaining a total in the database makes sense. Unfortunately, I am trying to add a small functionality to a much larger already-designed database. At some point I will have to re-design it if I am going to add any more functionality. I also see where it's running the query twice. Thank you!
  16. Hello all, I am having an issue with updating my database, and subtracting $seats_taken from a number in my database available_seats. When I run this script below, it subtracts 2 from available_seats instead of 1. Any ideas why it's doing that? <?php $seats_taken = "1"; // using this as an example $class_name = "Math"; // using this as an example if (isset($class_name) && $seats_taken > 0 && $seats_taken <= 11) { include "/path/to/login.php"; $db = new mysqli('localhost', $username, $password, $database); // Connect to DB using required login info if($db->connect_errno > 0) { die('Unable to connect to database [' . $db->connect_error . ']'); } unset($username);// put these variables back to null unset($password);// put these variables back to null unset($database);// put these variables back to null $sql = "UPDATE form_data SET available_seats = available_seats - $seats_taken WHERE class_name = '$class_name'"; $result = $db->query($sql); if(!$result = $db->query($sql)){ // if there is an error in running the query, show error message. die('There was an error running the query [' . $db->error . ']'); } $db->close(); } else echo "There was a problem updating the available seats."; ?>
  17. That's it, not sure why I had that in there. Thanks! Now I have to figure out why the number is going down by two and not one!
  18. I am trying to add a query to my script that updates a value in my database by subtracting "1". When I run the query, I get "Fatal error: Call to a member function free() on boolean in ../path/to/my/script" $sql = "UPDATE table_5 SET chairs = chairs - 1 WHERE chairs > 0 AND chair_model = 'model_33'"; Any idea what I'm doing wrong? Table 5: Chairs | Model Number | 22 | model_33 44 | model_44
  19. Hello all, I have a form that has a number field. It gets the max and min based on another dropdown selection. Next to the number field, I have a DIV that also changes to say what the max number is for that field. Then, I have a validator that will give an error if the person enters a number outside of that range. Min is always 1, and the max changes based not the other dropdown. It looks like this: [______] (17 seats available) If there is an error: [______] (Sorry, there are {0} seats available. Please select a number of seats between 1 and {0}) This is working great, but when someone selects a valid number, then my default text of (17 seats available) goes away. This normally wouldn't be an issue, but if they decide to change that original dropdown, the default text of available seats for that dropdown doesn't re-appear. I am wondering if I can set that default text to a "valid" response, meaning that if they select a valid number then the (17 seats available) text re-appears. Here's my js validation: jQuery.validator.setDefaults({ debug: true, success: "valid" }); $( "#registration" ).validate({ rules: { availabe_seats: { required: true, max:parseInt(available_seats) } } }); jQuery.extend(jQuery.validator.messages, { max: jQuery.validator.format(" <p style=\"color:red;display:inline\"> Sorry, there are {0} seats available. Please select a number of seats between 1 and {0}.</p>"), // display error message if there are not enough seats available. This validates number field to avoid manual entries. if using the up/down dial, it will not let the user select anything above the max anyway. }); jQuery.extend(jQuery.validator.messages, { min: jQuery.validator.format(" <p style=\"color:red;display:inline\"> Sorry, you must select at least one seat.</p>"), // display error message if there are not enough seats available. This validates number field to avoid manual entries. if using the up/down dial, it will not let the user select anything above the max anyway. }); Here's my html for where it goes: <input type="number" min="" max="" step="1" value="1" name="available_seats" id="available_seats"/> <label for="available_seats" class="error" generated="true"> (<div class="in-line"><div id="display_seats_available">0</div></div> Seats Available)<br /><br /></label> I also have additional js for the min max for the number input, and that works fine. The above js is really for the people that manually enter a number instead of using the number up/down button.
  20. Thanks for catching my label error and for the suggestion. I ended up doing this: <?php $counter = 0; for ($x = 1; $x <= 5; $x++) { $counter++; echo "Student " . $counter . ":"; echo "<div class=\"form_fields_enthusiast\"> <p><label for=\"Name\">Name:</label> <input name=\"First_Name_" . $counter . "\" type=\"text\" value=\"\" size=\"16\" maxlength=\"35\" placeholder=\"First\"/> <input name=\"Middle_Name_" . $counter . "\" type=\"text\" value=\"\" size=\"16\" maxlength=\"35\" placeholder=\"Middle\"/> <input name=\"Last_Name_" . $counter . "\" type=\"text\" value=\"\" size=\"16\" maxlength=\"35\" placeholder=\"Last\"/><span style=\"font-size:11px\">(Required)</span></p> <div style=\"display:none\"> <input type=\"text\" name=\"email_address_" . $counter . "\" value=\"\" /> </div> <p><label for=\"address_" . $counter . "\">Address:</label> <input name=\"Address_" . $counter . "\" type=\"text\" value=\"\" size=\"25\" maxlength=\"35\" placeholder=\"123 Main Street\"/> <input name=\"apt_" . $counter . "\" type=\"text\" value=\"\" size=\"4\" maxlength=\"5\" placeholder=\"APT\"/><span style=\"font-size:11px\">(Required)</span></label></p> <p><label for=\"City_" . $counter . "\">City:</label> <input name=\"City\" type=\"text\" value=\"\" size=\"16\" maxlength=\"35\" placeholder=\"San Francisco\"/> State: <input name=\"State\" type=\"text\" value=\"\" size=\"3\" maxlength=\"10\" placeholder=\"CA\"/> ZIP:<input name=\"Zip_" . $counter . "\" type=\"text\" value=\"\" size=\"10\" maxlength=\"10\" placeholder=\"94574\" /><span style=\"font-size:11px\">(Required)</span></label></p> <p><label for=\"home_phone_" . $counter . "\">Home Phone:</label> <input name=\"home_phone_" . $counter . "\" type=\"text\" value=\"\" size=\"16\" maxlength=\"18\" placeholder=\"555-555-5555\" /><span style=\"font-size:11px\">(Required)</span></label></p> <p><label for=\"cell_phone_" . $counter . "\">Cell Phone:</label> <input name=\"cell_phone_" . $counter . "\" type=\"text\" value=\"\" size=\"16\" maxlength=\"18\" placeholder=\"555-555-5555\" /><span style=\"font-size:11px\"></span></label></p> <p><label for=\"email_" . $counter . "\">Email:</label><input name=\"email\" type=\"text\" value=\"\" size=\"30\" maxlength=\"40\" placeholder=\"you@gmail.com\" /><span style=\"font-size:11px\">(Required)</span></label></p> <p><label for=\"birthday_" . $counter . "\">Date of Birth:</label> <input name=\"birthday\" type=\"text\" value=\"\" size=\"16\" maxlength=\"10\" placeholder=\"MM/DD/YYYY\" /><span style=\"font-size:11px\">(Required)</span></label></p> <p><label for=\"student_id_" . $counter . "\">Student ID#:</label> <input name=\"student_id_" . $counter . "\" type=\"text\" value=\"\" size=\"16\" maxlength=\"16\" placeholder=\"\" /></label></p> </div>"; } ?>
  21. Thank you for your help. My database doesn't necessarily need a name_underscore_number, but it needs a unique name associated with the form field. I am using a third party software that processes the form. I can then view the responses in an organized way with the backend of the program.
  22. I have a multi page form, in which the person selects the number of people to register for an event on page 1. That variable is passed on to page two. On page two, I would like to take the variable of number of people (ex. "3"). and display that number of sets of registration text fields. What makes it difficult is that each set needs to have a number appended to their input name in order to work with my database. Can anyone think of a way to do this? Below is an example of the html I have for the form fields I am duplicating. In this case, I have "1" appended to the form input names as an example. <div class="form_fields_enthusiast_1"> <p><label for="Name">Name:</label> <input name="First_Name_1" type="text" value="" size="16" maxlength="35" placeholder="First"/> <input name="Middle_Name_1" type="text" value="" size="16" maxlength="35" placeholder="Middle"/> <input name="Last_Name_1" type="text" value="" size="16" maxlength="35" placeholder="Last"/><span style="font-size:11px">(Required)</span></p> <div style="display:none"> <input type="text" name="email_address_1" value="" /> </div> <p><label for="address_1">Address:</label> <input name="Address_1" type="text" value="" size="25" maxlength="35" placeholder="123 Main Street"/> <input name="apt_1" type="text" value="" size="4" maxlength="5" placeholder="APT"/><span style="font-size:11px">(Required)</span></p> <p><label for="City_1">City:</label> <input name="City_1" type="text" value="" size="16" maxlength="35" placeholder="San Francisco"/> State: <input name="State_1" type="text" value="" size="3" maxlength="10" placeholder="CA"/> ZIP:<input name="Zip_1" type="text" value="" size="10" maxlength="10" placeholder="12345" /><span style="font-size:11px">(Required)</span></p> <p><label for="home_phone_1">Home Phone:</label> <input name="home_phone_1" type="text" value="" size="16" maxlength="18" placeholder="555-555-5555" /><span style="font-size:11px">(Required)</span></p> <p><label for="cell_phone_1">Cell Phone:</label> <input name="cell_phone_1" type="text" value="" size="16" maxlength="18" placeholder="555-555-5555" /><span style="font-size:11px"></span></p> <p><label for="email_1">Email:</label><input name="email" type="text" value="" size="30" maxlength="40" placeholder="you@gmail.com" /><span style="font-size:11px">(Required)</span></p> <p><label for="birthday_1">Date of Birth:</label> <input name="birthday" type="text" value="" size="16" maxlength="10" placeholder="MM/DD/YYYY" /><span style="font-size:11px">(Required)</span></p> <p><label for="student_id_1">Student ID#:</label> <input name="student_id_1" type="text" value="" size="16" maxlength="16" placeholder="" /></p> </div>
  23. I have a MySQL database that includes class name, class number, cost, description, and seats available. My current script has a dropdown menu for the class name. Based on the dropdown selection, the fields for class number, cost, and description change. Now, I want to create a dropdown for the number of seats available. What I want to display is a dropdown list from 1 to number_of_seats_available (The database contains a number of seats available for each class.) For instance, if there are 4 (four) seats left, the dropdown will show: 1 2 3 4 If there are 6 seats left, the dropdown will show 1-6. I would normally do this with PHP with a foreach loop like: foreach(range(1,$seats_available) as $seats_dropdown){ echo "<option value='$seats_dropdown'>$seats_dropdown</option>\n";} But this needs to be dynamic like the rest of the script, based on the class that is selected in the first dropdown. I did some searching and couldn't find anything that matched my needs. Anyone point me in the right direction? Here's what I have so far for the rest of the form: <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script> // using jquery to apply an onchange event on the select element named class_drop_down $('select[name="class_drop_down"]').on('change', function() { // do an ajax request to get_class_details.php, passing selected the class name $.ajax({ url: 'get-classes-for-registration-php-beta.php', method: 'POST', data: { class_name: $(this).val()}, dataType: 'json', // this function is called with the response from the request success: function(response) { // make sure a error was not returned if(response.error === undefined) { // set values for class number and date fields as follows $('input[name="course_number"]').val(response.course_number); $('input[name="course_start_date"]').val(response.class_start_date); $('input[name="class_start_time"]').val(response.class_start_time); $('input[name="cost"]').val(response.cost); $('#class_description').html(response.class_description); $('#instructor').html(response.Instructor); } else { // demo purposes only, output error message as an alert alert(response.error); } }, }); }); </script>
  24. Great responses, thank you. Still learning lots, and that helps tons!
  25. Ok, here's my latest dilemma. If anyone has any suggestions, I would love to hear them. I am not looking for someone to code this for me, just a point in the right direction. I have a value in my MySQL database that is a number between 1 and 50 ($number_value). When the page loads, I want to use that value to create a dropdown list from 1 to $number_value. I could create a script that checks for $number_value for each possible situation, but that would be a pretty long and probably not the most efficient. Any other ideas? So you know what I am talking about, this is just a text representation: If $number_value is 5, echo: <option value=“1">1</option> <option value=“2">2</option> <option value=“3">3</option> <option value=“4">4</option> <option value=“5">5</option> If $number_value is 3, echo: <option value=“1">1</option> <option value=“2">2</option> <option value=“3”>3</option> If $number_value is 10, echo: <option value=“1">1</option> <option value=“2">2</option> <option value=“3”>3</option> <option value=“4">4</option> <option value=“5">5</option> <option value=“6”>6</option> <option value=“7">7</option> <option value=“8">8</option> <option value=“9”>9</option> <option value=“10”>10</option>
×
×
  • 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.