Jump to content

idontknowphp

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

About idontknowphp

  • Birthday 12/02/1984

Profile Information

  • Gender
    Male

idontknowphp's Achievements

Member

Member (2/5)

0

Reputation

  1. I am aware of that, I was posting only the pertinent code....here is the whole "form" portion: <form id="theform" action="manage-products.php?action=addProduct" method="post"> <input type="text" name="p_name" id="p_name"/> <textarea name="p_desc"></textarea> <input "name="submit" type="submit" value="Create Product"/> <ul class="categories"> <?php $query = "SELECT * FROM products"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $category = $row['category']; $catId = $row['id']; echo "<li><input class='catCheck' type='checkbox' name='p_cat[]' value='$catId' /> $category</li>"; } ?> </ul> </form>
  2. I have figured out far enough to loop through my table and return a list of check boxes that will be matched to a product. My issue now, is i cannot figure out the proper way to loop through them after they are selected and return them as checked/unchecked for the given product. Thought there is some MySQL involved, that part isn't the problem, I know how to insert into a database or update...when the product is selected from a drop down, I need to be able to populate the checkboxes. Here is the code i am using to initially display all of the categories to choose from... <ul class="categories"> <?php $query = "SELECT * FROM products"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $category = $row['category']; $catId = $row['id']; echo "<li><input class='catCheck' type='checkbox' name='p_cat[]' value='$catId' /> $category</li>"; } ?> </ul> Thanks guys....
  3. What happened was I tried to do it myself, but i don't think i grasped the concept of how to process the post/get properly...Instead of properly porcessing "manage-products.php?action=newProduct" it would instead not process it at all and would tack on "manage-categories.php?category=Test&submit=Add+Categories"...I just was hoping someone with more background could look at it and say "duh retard, that's not how you do it..." But i realize i forgot to post what i tried to use as far as the jQuery...here is the code again with jQuery $("#theform").submit(function(event) { var $form = $(this), $inputs = $form.find("input, select, button, textarea"), serializedData = $form.serialize(); $inputs.attr("disabled", "disabled"); $.ajax({ url: "manage-products.php?action=newProduct", type: "post", data: serializedData, success: function(response, textStatus, jqXHR) { console.log("Win."); }, error: function(jqXHR, textStatus, errorThrown) { console.log("Fail: " + textStatus, errorThrown); }, complete: function() { $inputs.removeAttr("disabled"); } }); event.preventDefault(); }); <form id="theform"> <input name="category" type="text" /> <input class="btn_add" name="submit" type="submit" value="Add Categories"/> </form> <?php if (isset($_POST['submit'])) { if (!empty($_POST['category'])) { if ($_GET['action'] == 'newCategory') { $categories = $_POST['category']; $query = "SELECT * FROM categories WHERE category ='$categories' "; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result)) { echo '<script>alert("The Following Catergories Already Exist: ' . $categories . '")</script>'; } else { $clean = str_replace(' ', '', $categories); $array = explode(",", $clean); foreach ($array as &$newCategory) { mysql_query("INSERT INTO categories (category) VALUES ('$newCategory')"); } echo "<script>alert('The following Categories have been added successfully: " . $categories . "')</script>"; } } } else { echo "<script>alert('Please Enter at Least One Category.')</script>"; } } ?>
  4. I am kicking myself in the arse here because i can't for the life of me figure it out...this is supposed to be a quick and dirty project, but, I decided i want to try something new, and I have little to no experience with the AJAX methods in jQuery...I spent quite literally 5 days trying to learn and understand how to appropriately implement the AJAX calls, but to know avail...I learned some basic stuff, but not what i need to execute the code below. Again, I am wondering how to go about converting this standard request to AJAX using jQuery... here is my form & php HTML: <form action="categories.php?action=newCategory" method="post"> <input name="category" type="text" /> <input name="submit" type="submit" value="Add Categories"/> </form> PHP: <?php if (isset($_POST['submit'])) { if (!empty($_POST['category'])) { if ($_GET['action'] == 'newCategory') { $categories = $_POST['category']; $query = "SELECT * FROM categories WHERE category ='$categories' "; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result)) { echo '<script>alert("The Following Catergories Already Exist: ' . $categories . '")</script>'; } else { $clean = str_replace(' ', '', $categories); $array = explode(",", $clean); foreach ($array as &$newCategory) { mysql_query("INSERT INTO categories (category) VALUES ('$newCategory')"); } echo "<script>alert('The following Categories have been added successfully: " . $categories . "')</script>"; } } } else { echo "<script>alert('Please Enter at Least One Category.')</script>"; } } ?> Thanks a lot guys, I really appreciate it.
  5. I was kind of looking for a little direction, I have scoured the internet and exhausted every other resource I could think of before coming here... Does anyone know of any classes or resources that have some solid explanation or can give an explanation on how to go about searching within a PDF file?? I have literally beren trying to figure it out for over a year...I need to wrap this up it is consuming my life. All help is greatly appreciated, thanks in advance
  6. While that did solve the error, not all of the items are being echoed back...I put in 9 items and got back 3 Seriously thanks for the quick response though...I really appreciate it.
  7. This is what I have now...im getting an undefined offset error, but $i should be set....unless my loop is a fail? I don't know... <form action="<?php echo $_SERVER['PHP_SELF']; ?>"method="post"> <label>URLs delimited by a COMMA</label> <textarea name="urls"></textarea> <input name="submit" type="submit" value="Submit" /> </form> <?php if (isset($_POST['submit'])) { $urls = trim($_POST['urls']); // remove white space from user input $arr = explode( ",", $urls); // convert the input into an array $count = count($arr); // count the number of items in the array for ($i = 0; $i <= $count; $i++) { // setup the loop to stop iteration when $count is met echo '<pre><a href="' . $arr[$i] . '>' . $arr[$i] . '</a></pre>'; // Hopefully echo the link list back if all goes well... } } ?>
  8. sorry solved this one, I didnt put the submit button in the <form> </form> tag lmfao...
  9. I reverted back to the original code....for starters. Well, this is based off of an excel file that I am trying to convert over to a php application... I attached it in a zip so you can see it working... That excel file will answer all the questions....I already converted all of the formulas into PHP conditionals, I just don;t know how to make the form functional... Again, once you see the form in action it will make plenty of sense Thanks again! [attachment deleted by admin]
  10. Well, though you explained it nicely, I am having a lot of problems....The main one being I am trying something that is quite difficult for my skill level. I just don;t understand how to make it all work together in my application....I have tried everything and I think all i have done is ruin the code.
  11. Though that made sense, I am a little confused in how i will make it all work together as a whole and how to properly call the function, can you either give me a few more hints or point me toward some literature so i can figure this out?
  12. I feel so dumb right now...I have only minimal knowledge of PHP, i am still trying to learn on my own thank you so much man, I should have known.
  13. Ok, that is fine....Here is the code: index.php - HTML for the user form (not styled, just the framework) <? require('functions.php'); ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="ezShipForm"> <!-- Begin Business & Contact Info ---> <input name="company" type="text" placeholder="Company"><br> <input name="address" type="text" placeholder="Address"><br> <input name="city" type="text" placeholder="City"><br> <select name="state"> <option value="0">State</option> <?php echo generateStateOptions($stateList); ?> </select><br> <input name="zipcode" type="text" placeholder="Zip Code"><br> <input name="contactPhone" type="text" placeholder="Contact Phone"><br> <input name="contactFax" type="text" placeholder="Contact Fax"><br> <input name="contactName" type="text" placeholder="Contact Name"><br> <input name="contactEmail" type="text" placeholder="Contact E-mail"><br> <!-- End Business & Contact Info ---> <!-- Begin Calculations ---> <input name="fuelPrice" type="text" placeholder="Today's Fuel Rate"> http://www.eia.gov/oog/info/wohdp/diesel.asp<br> <select name="trailerType"> <option value="Flat Bed">Flatbed</option> <option value="Step Deck">Step Deck</option> <option value="Van">Van</option> <option value="Refer">Refer</option> <option value="RGN/Lo-Boy">RGN/Lo-Boy</option> </select> <br> <input name="pickUpDate" type="text" placeholder="MM/DD/YYYY"><br> <input name="startingCity" type="text" placeholder="Starting City"><br> <select name="startingState"> <option value="0">State</option> <?php echo generateStateOptions($stateList); ?> </select><br> <input name="destinationCity" type="text" placeholder="Destination City"><br> <select name="destinationState"> <option value="0">State</option> <?php echo generateStateOptions($stateList); ?> </select><br> <input name="loadedMiles" type="text" placeholder="Loaded Miles">http://www.truckmiles.com/<br> <select name="loadType"> <option value="Full">Full</option> <option value="Partial">Partial</option> </select><br> <select name="loadSize"> <option value="Yes">Oversized</option> <option value="No">Not Oversized</option> </select><br> <input name="loadLength" type="text" placeholder="Load Length">Ex: 120in = 10ft<br> <input name="loadWeight" type="text" placeholder="Weight">Ex: 10500lbs = 10.5<br> <input name="loadWidth" type="text" placeholder="Load Width">in inches<br> <input name="loadHeight" type="text" placeholder="Load Height">in inches<br> <select name="tarped"> <option value="Yes">Yes</option> <option value="No">No</option> </select><br> <select name="twicCardReq"> <option value="Yes">Yes</option> <option value="No">No</option> </select><br> <input name="permits" type="text" value="0">If yes, How many states?<br> <input name="pilotCars" type="text" value="0">If yes, How many?<br> <input name="loadDescription" type="text" placeholder="Brief Load or Product Description"><br> <input name="comments" type="text" placeholder="Other Comments"><br> <input name="total" type="text"><br> <input name="submit" type="submit" value="Submit"> <input name="overWidth102" type="hidden"> <input name="overWidth120" type="hidden"> <input name="overWidth144" type="hidden"> <input name="overWidth168" type="hidden"> <input name="overLength52" type="hidden"> <input name="overLength56" type="hidden"> <input name="overLength58" type="hidden"> <input name="overLength60" type="hidden"> <input name="overLength62" type="hidden"> </form> <?php if (isset($_POST['submit'])) { //Call the 'performCalculation' Function To Get Total Coat performCalculation(); } ?> </body> </html> functions.php <?php function performCalculation() { //Declare User Form Variables $company = $_POST['company']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zipcode = $_POST['zipcode']; $contactPhone = $_POST['contactPhone']; $contactFax = $_POST['contactFax']; $contactName = $_POST['contactName']; $contactEmail = $_POST['contactEmail']; $fuelPrice = $_POST['fuelPrice']; $trailerType = $_POST['trailerType']; $pickUpDate = $_POST['pickUpDate']; $startingCity = $_POST['startingCity']; $startingState = $_POST['startingState']; $destinationCity = $_POST['destinationCity']; $destinationState = $_POST['destinationState']; $loadedMiles = $_POST['loadedMiles']; $loadType = $_POST['loadType']; $loadSize = $_POST['loadSize']; $loadLength = $_POST['loadLength']; $loadWeight = $_POST['loadWeight']; $loadWidth = $_POST['loadWidth']; $loadHeight = $_POST['loadHeight']; $tarped = $_POST['tarped']; $twicCardReq = $_POST['twicCardReq']; $permits = $_POST['permits']; $pilotCars = $_POST['pilotCars']; $loadDescription = $_POST['loadDescription']; $comments = $_POST['comments']; $overWidth102 = $_POST['overWidth102']; $overWidth120 = $_POST['overWidth120']; $overWidth144 = $_POST['overWidth144']; $overWidth168 = $_POST['overWidth168']; $overLength52 = $_POST['overLength52']; $overLength56 = $_POST['overLength56']; $overLength58 = $_POST['overLength58']; $overLength60 = $_POST['overLength60']; $overLength62 = $_POST['overLength62']; $total = $_POST['total']; //Declare Calculation Variables $mainRate = ($fuelPrice * 0.166 + 1.06) * 1.25; $mileRate = $loadedMiles * $mainRate; $permitRate = $permits * 50; $pilotCarRate = ($pilotCars * 1.25 * $loadedMiles); $flatBedRate = $subTotal; $overSizeRate = $overWidth102 + $overWidth120 + $overWidth144 + $overWidth168 + $overLength52 + $overLength56 + $overLength58 + $overLength60 + $overLength62; //Surcharge Calculation if ($loadedMiles < 500) { $surcharge = (500 - $loadedMiles) * .25 * $mainRate; } //Load Rate Calculation if ($loadLength > $loadWeight) { $loadRate = $loadLength * $loadedMiles * ($mainRate / 34); } else { $loadRate = $loadWeight * $loadedMiles * ($mainRate / 34); } //Tarped Rate Calculation if ($tarped == "Yes") { $tarpRate = 100; } else { $tarpRate = 0; } //Sub Total Calculation if ($loadSize == "Full") { $subTotal = $loadedmiles + $surcharge + $tarpRate + $permitRate + $pilotCarRate; } else { $subTotal = $surcharge + $loadRate + $tarpRate + $permitRate; } //Step Deck Rate Calculation if ($trailerType == "Step Deck") { $trailerRate = $subTotal * .02; } //Van Rate Calculation if ($trailerType == "Van") { $trailerRate = $subTotal * .02; } //Refer Rate Calculation if ($trailerType == "Refer") { $trailerRate = $subTotal * .04; } //RGN/Lo-Boy Rate Calculation if ($trailerType == "RGN/Lo-Boy") { $trailerRate = $subTotal * .10; } //Over Width Rate Calculations if ($loadWidth > 102) { $overWidthRate = $loadedMiles * .2; } if ($loadWidth > 120) { $overWidthRate = $loadedMiles * .1; } if ($loadWidth > 144) { $overWidthRate = $loadedMiles * .1; } if ($loadWidth > 168) { $overWidthRate = $loadedMiles * .1; } //Over Length Rate Calculations if ($loadLength > 52) { $overWidthRate = $loadedMiles * .14; } if ($loadLength > 56) { $overWidthRate = $loadedMiles * .07; } if ($loadLength > 58) { $overWidthRate = $loadedMiles * .07; } if ($loadLength > 60) { $overWidthRate = $loadedMiles * .07; } if ($loadLength > 62) { $overWidthRate = $loadedMiles * .07; } // Total Rate Calculation if ($loadedMiles !== 0) { $total = $trailerRate + $overSizeRate; echo $total; } else { $total = 0; } } //Generate List of States $stateList = array ('alabama'=>"AL", 'Alaska'=>"AK", 'Arizona'=>"AZ", 'Arkansas'=>"AR", 'California'=>"CA", 'Colorado'=>"CO", 'Connecticut'=>"CT", 'Delaware'=>"DE", 'District Of Columbia'=>"DC", 'Florida'=>"FL", 'Georgia'=>"GA", 'Hawaii'=>"HI", 'Idaho'=>"ID", 'Illinois'=>"IL", 'Indiana'=>"IN", 'Iowa'=>"IA", 'Kansas'=>"KS", 'Kentucky'=>"KY", 'Louisiana'=>"LA", 'Maine'=>"ME", 'Maryland'=>"MD", 'Massachusetts'=>"MA", 'Michigan'=>"MI", 'Minnesota'=>"MN", 'Mississippi'=>"MS", 'Missouri'=>"MO", 'Montana'=>"MT", 'Nebraska'=>"NE", 'Nevada'=>"NV", 'New Hampshire'=>"NH", 'New Jersey'=>"NJ", 'New Mexico'=>"NM", 'New York'=>"NY", 'North Carolina'=>"NC", 'North Dakota'=>"ND", 'Ohio'=>"OH", 'Oklahoma'=>"OK", 'Oregon'=>"OR", 'Pennsylvania'=>"PA", 'Rhode Island'=>"RI", 'South Carolina'=>"SC", 'South Dakota'=>"SD", 'Tennessee'=>"TN", 'Texas'=>"TX", 'Utah'=>"UT", 'Vermont'=>"VT", 'Virginia'=>"VA", 'Washington'=>"WA", 'West Virginia'=>"WV", 'Wisconsin'=>"WI", 'Wyoming'=>"WY"); //Generate State Options for User Forms function generateStateOptions($array) { $string = ''; foreach($array as $k => $v) { $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n"; } return $string; } //End of file ?>
×
×
  • 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.