Jump to content

DeX

Members
  • Posts

    258
  • Joined

  • Last visited

Everything posted by DeX

  1. Hi guys, I'll try to explain this. I'm doing a quoting system for a building contractor and I have a dynamic purchase order created for every quote that's confirmed and it spits out all the materials they will need for each supplier. The layout of the page is exactly what I need emailed to the supplier so they can ship out the materials listed, it's your basic purchase order. I'm going to put a button on the page that sends the email to the supplier but I need to attach the purchase order displayed on the page. Preferably in PDF but it just needs to be an attached file. I know I can have the user use PRINT.... to save it as PDF and then use Outlook to email it but I'd like to automate it. Thanks.
  2. Hi guys, I have a system that does quotes for jobs for customers. The user inputs a customer's information and then the options they want on their building and it stores the quote in the database into a quote table. I have some questions regarding the best way to do this: 1. Should I enter the customer ID into the quote table or enter the quote ID into the customer table for reference? 2. Either way, how do I get that ID to enter into the reference table? I have the primary key ID set to auto_increment for both tables, how do I know what the ID is going to be so I can store it in the other table? 3. What's the best way to perform both of these SQL statements but not commit them until everything is okay? Thanks.
  3. This works as a function: function takeOut(id) { var parent3 = document.getElementById('formitem' + id); var old = (parent3.parentNode).removeChild(parent3); } , does this look okay? It does work. I also had to add a 'return false' to the button onClick event so it didn't submit the form as well.
  4. I just tried that and it almost worked. When I clicked the X it removed the element but then it submitted the form too.....you know how it does that whenever there's an error? Know what I mean? I changed the code a bit, here's the function I used from you: <script type="text/javascript"> function takeOut(id) { var parent3 = document.getElementById('formitem' + id); var old = parent3.removeChild(parent3.childNodes[0]); } </script> And here's a screenshot of the elements on the page. I couldn't post the source code because this is on one of the elements that was added with Javascript so it's not in the source. Hope I gave you enough to help me. Thanks. [attachment deleted by admin]
  5. Here's the source code from my page, I have many of these form-item elements going down the page and also a button to be able to add more next to their respective siblings. Now I need a button to remove any that are added by mistake, how can I do that? Source code: <formitem id = 'formitem20'> <div class='form-item'> <label for=''>Deck</label> <select name='form1[23][DeckWidth]'> <option value=''>W</option><option value='0'>0</option> <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> </select><input type='hidden' name='form1[23 value='' /> <select name='form1[23][DeckLength]'> <option value=''>L</option><option value='0'>0</option> <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> </select> <input type='hidden' name='form1[23 value='' /> <button onClick='addRow(21, "20", "Deck", 0, 1, 1, 0);return false;'>..</button> <button onClick='takeOut('20');return false;'>X</button> </div> </formitem> <br /> I already have the button there for removing the element and it goes to a Javascript function like so: <script type="text/javascript"> function takeOut(id) { var parent = document.getElementsByTagName('formitem')[id]; var old = elem.removeChild(elem.childNodes[0]); } </script> The javascript is probably way off, I've changed it about 100 times and it never works. I have no idea how it's supposed to look, nor even how to get a hold of the proper element I need. Each element's ID increments so this one is in spot 23 of the array and is called DeckWidth. The next one would be 24 and be called DeckLength and so on. Thanks guys.
  6. You guys are awesome, thanks. I have another question now, what if I wanted to add checkboxes? I set up the columns in the database to be of type BOOL because they're either on or off. There's a screenshot at the bottom of the columns I added on the web page and here's the code that I took from earlier in this thread and modified a bit. The delete checkbox on the far right works, I'm trying to get the middle 4 to input their true/false values into the database for checked/unchecked. if (isset($_POST['saveChanges'])) { $form = $_POST['form1']; $query3 = "DELETE from options where id = "; $deleteCount = 0; $deleteRows = false; // Santize $form, make sure its an array etc.. // Loop array foreach($form as $rowid => $columnarray) { // set query start $query = "UPDATE options SET "; $query2 = "INSERT into options (name, materialsPrice, labourPrice, weight, sku) VALUES ('"; $count = 0; // Loop each column for this row foreach($columnarray as $column => $value) { if ($value == 'delete') { $deleteRows = true; if ($deleteCount == 0) { $query3 .= $rowid; $deleteCount += 1; } else { $query3 .= " or id = " . $rowid; } } else { if ($count == 0) { if ($value == '') { $query2 .= "0'"; } else { $query2 .= $value . "'"; } // Add set phrase to query $query .= $column."='".$value."' "; $count = $count + 1; } else { if ($value == '') { $query2 .= ", 0"; } else { $query2 .= ", " . $value; } // Add set phrase to query // if ($column == 'quantityCheckbox') // { // $value = "off"; // } $query .= ", " . $column."='".$value."' "; } } } // End query: $query .= "WHERE id='".$rowid."'"; $query2 .= ")"; $checkForRow = @mysql_query("select * from options where id = '".$rowid."'"); if(mysql_num_rows($checkForRow) > 0) { echo $query; $updateTable = $db->query($query); } else { $insertValues = $db->query($query2); } } if ($deleteRows) { $deleteRowsResult = $db->query($query3); } } <? $count2 = 1; foreach ($all_rows as $column) { print ("<tr>"); print ("<td>". $column['name'] . "</td>"); print ("<td><input type='text' name='form1[".$column['id']."][materialsPrice]' id='".$column['id']."' value='".$column['materialsPrice']."'/> <input type='hidden' name='form1[".$column['id']."' value='"."' /></td>"); print ("<td><input type='text' name='form1[".$column['id']."][labourPrice]' id='".$column['id']."' value='".$column['labourPrice']."'/> <input type='hidden' name='form1[".$column['id']."' value='"."' /></td>"); print("<td><input type = 'checkbox' name = 'form1[".$column['id']."][quantityCheckbox]' id = '".$column['id']."' checked = '".$column['quantityCheckbox']."' value = '".$column['quantityCheckbox']."'/> <input type='hidden' name='form1[".$column['id']."' value='"."' /></td>"); print("<td><input type = 'checkbox' name = 'form1[".$column['id']."][widthCheckbox]' id = '".$column['id']."' checked = '".$column['widthCheckbox']."' value = '".$column['widthCheckbox']."'/>"); print("<td><input type = 'checkbox' name = 'form1[".$column['id']."][lengthCheckbox]' id = '".$column['id']."' checked = '".$column['lengthCheckbox']."' value = '".$column['lengthCheckbox']."'/>"); print("<td><input type = 'checkbox' name = 'form1[".$column['id']."][heightCheckbox]' id = '".$column['id']."' checked = '".$column['heightCheckbox']."' value = '".$column['heightCheckbox']."' /> "); print ("<td><input type='text' name='form1[".$column['id']."][weight]' id='".$column['id']."' value='".$column['weight']."'/> <input type='hidden' name='form1[".$column['id']."' value='"."' /></td>"); print ("<td><input type='text' name='form1[".$column['id']."][sku]' id='".$column['id']."' value='".$column['sku']."'/> <input type='hidden' name='form1[".$column['id']."' value='"."' /></td>"); print ("<td><input type='checkbox' name='form1[".$column['id']."][delete]' id='".$column['id']."' value='delete'/> <input type='hidden' name='form1[".$column['id']."' value='"."' /></td>"); print ("</tr>"); $count2 += 1; } ?> </tbody> </table> <div id="subnav"> <input type="hidden" name="saveChanges" id="saveChanges" value="saveChanges" /> <input type="submit" name="submit" value="Save" class="logout" /> <?php echo "<button onClick='addRow(".$count2.");return false;'>Add Row</button>" ?> Columns for middle 4 checkboxes are: - quantityCheckbox - widthCheckbox - lengthCheckbox - heightCheckbox [attachment deleted by admin]
  7. Very interesting way of doing this, thank you! And yes, 2x4 is a product, it's the width/depth measurements of a piece of lumber, pronounced two by four.
  8. I can't figure out how to edit my post. Here's what I did. Is this right? // Loop each column for this row foreach($columnarray as $column => $value){ if ($count == 0) { // Add set phrase to query $query .= $column."='".$value."' "; $count = $count + 1; } else { // Add set phrase to query $query .= ", " . $column."='".$value."' "; } } And I set the count to 0 again outside the loop.
  9. Actually I spoke too soon. I tried it for a form with multiple input columns and get this error on the page: You can see it's missing the comma between the assignments, otherwise it works fine. How do I display the comma in there?
  10. What if the calculation itself changes? What if now they want to multiply all costs by 2? Or instead of the number of 2x4 being equal to the length of the building, now the quantity will be something like (length * 2) / 3?
  11. Say I have a client who wants to do quotes for a building. They offer 2 building sizes with the following requirements (example) for materials: 1. Building A requires 5 2x4 and a window. 2. Building B requires 7 2x4 and 3 windows. That's all good, I can put the relative prices for each material in the database and there's an equation to figure out which building requires how many of each material, that's fine. But how could I build this so that the client can go in afterwards and change it so Building B requires 8 2x4? How about if he now wants to offer doors as well for his buildings? Right now I get the required quantities of each material through a series of calculations and then I add/multiply what's needed to get all materials for the building and the total cost. That's all done in the PHP code. How can I make it editable by a client who doesn't know code?
  12. Thanks, that worked beautifully! You guys are quick.
  13. Simple question, I know. I have a form that's built dynamically like so: foreach ($all_rows as $column){ print ("<tr>"); print ("<td>". $column['id'] . "</td>"); print ("<td>". $column['name'] . "</td>"); print ("<td><input type='text' name='".$column['id']."' id='".$column['id']."' value='".$column['pricePerPiece']."'/></td>"); print ("<td><input type='text' name='weight' id='weight' value='".$column['weight']."'/></td>"); print ("<td>". $column['sku'] . "</td>"); print ("</tr>"); } I left out some of the table structure but the page works fine, I know how to do that part. So I have the input field for pricePerPiece in that column and all the values are loaded from the database. I need to get those values and update the database if the user changes any of them. So what I'm doing right now is I set the name/ID of each input box to be the database ID of that item and I'll update the database where the ID equals that value. The problem is when I submit it, how do I get all the input values and then loop through them to update the database with each one? I've attached a screenshot of the page. [attachment deleted by admin]
  14. I got it working. With Wordpress there's an index.php page in the root directory and a line of code in there that simply specifies whether or not you're using a template and then references the index.php from the template folder. Instead of putting the session check in this root index page, I had to put it at the top of the template's index page. Thanks, everyone!
  15. Hmmm.......nope. I go to www.mydomain.com/intranet/ and log in, works great. Then I add /blog/ into the address bar and that brings me to the blog as a logged in user, great. Then I delete the /blog/ from the address bar and it asks me to log in again. This is without using any links, just manually entering the addresses myself.
  16. Thanks, all I had to do was add the exit; code and it worked perfect. Now there's one last problem. I changed the code on all the /intranet/ pages and also the /intranet/blog/ pages to be: <? require('includes/config/config.inc.php'); require('includes/classes/Database.class.php'); require('intranet/includes/func.php'); session_start(); /********************************* ****************** LOGIN CHECK ***************************************************/ if (isset($_SESSION['auth'])){ } else { header("Location: ../intranet/index.php?error=noauth"); exit; } ?> Only the blog has the ../ part of the relative path, the intranet doesn't have it for obvious reasons.....because it's a relative path. So I go to the /intranet/ site and it asks me to log in, great. I log in and it allows me to navigate around /intranet/, great. I click the link to go to the /intranet/blog/ and that works, great. I click the link to go back to /intranet/ and it asks me to log in again. What have I got done now?
  17. I added this script: if (isset($_SESSION['auth'])){ echo "1"; } else { echo "2"; } ?> and it works perfect. When I'm logged in it will show a 1 and when I'm logged out it'll show a 2. So I added a redirect to bring the user back to the login page if they're not logged in like so: if (isset($_SESSION['auth'])){ } else { header("Location: ../intranet/index.php?error=noauth"); } ?> ...and it doesn't work. Instead of redirecting to the login page, it just loads the blog as if there were no redirect at all. What did I do wrong?
  18. Thank you, I'll try that when I get home. Maybe the extra database check is causing it to fail. Should your solution work for subdirectories as well?
  19. Thanks for the reply. Don't I have to? I need to see if the variable is set and then if it equals a valid login value for that user. Would you suggest another way?
  20. Hi, I have a website with the following structure: www.mydomain.com - main public site www.mydomain.com/intranet - internal site locked down with login script www.mydomain.com/intranet/blog - internal blog should be locked down by same script as intranet So I added a login script to the index.php page of /intranet/ and to every other page I added a check script as outlined below: <? require('includes/config/config.inc.php'); require('includes/classes/Database.class.php'); require('intranet/includes/func.php'); session_start(); /********************************* ****************** LOGIN CHECK ***************************************************/ if (isset($_SESSION['auth'])){ $db3 = new Database($config['server'], $config['user'], $config['pass'], $config['database']); $db3->connect(); $sql3 = "SELECT * FROM member WHERE auth='" . $_SESSION['auth'] ."'"; $row3 = $db3->query_first($sql3); if($_SESSION['auth'] != $row3['auth'] || $row3['access'] != "0"){ header("Location: index.php?error=badlogin"); } } else { header("Location: index.php?error=noauth"); } $db = new Database($config['server'], $config['user'], $config['pass'], $config['database']); $db->connect(); $sql ="SELECT * FROM member"; $row = $db->query($sql); $users = $db->fetch_all_array($sql); $count = $db->affected_rows; $db2 = new Database($config['server'], $config['user'], $config['pass'], $config['database']); $db2->connect(); $sql2 ="SELECT * FROM filesecure"; $row2 = $db2->query($sql2); $count2 = $db2->affected_rows; ?> Now this code works perfect for the /intranet/ directory, login/logout works fine. My problem is I added the same script, with "../" in front of the file references, to the /intranet/blog/ directory and it won't accept that I'm logged in. It boots me out to the login page again. Even if I try to navigate to the /intranet/blog/index.php page, it'll redirect me to the /intranet/index.php page to log in like it should. I log in, then it brings me to the /intranet/home.php page like it should once I'm logged in. Then I click a link to get to /intranet/blog/index.php and it redirects me to the login page again. Why doesn't it realize I'm logged in? Does the session() variable not work for subdirectories? For what it's worth, the /intranet/blog/ directory is built on a Wordpress install and I added the login check script to the top of the index.php page for the template I'm using. Thanks!
  21. I know how to do this, I'll try and remember to get back to you later tonight when I have time. I've done it one 2 sites already and it's really quite simple.
  22. Okay thanks. So my new checklogin.php looks like so: <?php ob_start(); $host="localhost"; // Host name $username="*********"; // Mysql username $password="********"; // Mysql password $db_name="*********"; // Database name $tbl_name="member"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE email='$myusername' and rawpass='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername'] = $myusername; $_SESSION['mypassword'] = $mypassword; $_SESSION['auth'] = 1; header("location:index.html"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> The problem is it's still not working. I've been staring at the code and can't figure out why it keeps redirecting me to index.php?=noauth. Here's some more things that might help you help me: - In the index.html there's a full page worth of HTML code below that PHP function. So is it correct to assume if the function exits properly that it won't redirect at all and will display the page? - The file is named index.html even though it has a PHP function in it. It seems to work as it is redirecting, could this cause issues? - The function is redirecting to index.php?=noaccess if true and index.php?=noauth if false. At least that's what it seems to me, is there any way for this type of if/else to not redirect to one of these pages? The guy before me built the index.html page so I didn't want to modify it too much. Or at all.
  23. I'm working on a members' login script but cannot seem to figure this out. The site currently has a bunch of html pages with this at the top: So I'm writing a PHP script on a login page to take advantage of this. My login page has a simple table: And another checklogin.php page: Now it functionally works, I just edited out the database information. It does the check and then redirects to index.html but then redirects to index.php?=noauth every time. I can't figure it out, it's looking for the "auth" variable to be assigned in the session which it is. What am I missing? Here's my database columns: The username for my user is "myusername" and the password is "mypassword".
×
×
  • 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.