Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. No. You would have to use JavaScript to do that. The JQuery UI framework has some prebuilt solutions that might meet your need. Here is one: http://jqueryui.com/autocomplete/#custom-data Or, if you don't want to complicate things, the common standard is to have a select list with the current options as well as a "Custom" option. Then have a text field for the user to enter that custom value.
  2. And what have you done thus far? A simple google search would yeild tons of resources and tutorials: http://lmgtfy.com/?q=php+export+excel
  3. I was going to try and help and started analyzing the information you have provided, but the information is all over the place and impossible to follow. For example, You have the following in your information Yet you show no such fields existing in those tables. In describing the fields for table 'driver' you have the following statement I'm confused. Is that a field in the table or not. Take a step back and look at what you have as someone who has not been working on the problem and figure out what information you would need to understand it. It seems to me that your "explanation" probably makes perfect sense to you, but you're not looking at it as someone with no prior knowledge of what you are doing (i.e. US).
  4. There are may ways. The hard way is to 'lock' the record when someone opens it to be edited. But, with a stateless application such as a web interface that introduces a whole host of problems to solve. The easier way is to allow any (authorized) user to open the record for editing. But, when you pull the information from the database, also pull a last updated timestamp. Then when they go to save verify that the timestamp is the same. If not, someone saved changes to the record since they opened it.
  5. Yeah, right. It absolutely makes sense for you to create a script to scrape the images from one of YOUR sites. So much easier than just copying the images from the server directly.
  6. Which is exactly why you should not delete/remove them, nor should you reuse a number. You should think of an invoice number like a checkbook. If you start to write a check and screw up, you just void that check and make a note of it in your register. You don't try to reuse that number by changing the number on the next check. If an invoice is invalid or otherwise unneeded, then change its status to deleted, voided, whatever and just leave it in the table. No need to move the record to a new table. You are making this harder than it needs to be.
  7. So, why do you need to reuse a number when the last one is deleted vs. an earlier one deleted? You're definitely making this harder than it needs to be. If you need the number preceded with a text value then you should do that in the presentation logic rather than the database. If you include the text in the database it makes this near impossible. Again, I would just have a numeric Primary ID column and use that and not worry about sequential numbering when items are deleted. In fact, I wouldn't ever delete them if the ID is that important - just update them to a "deleted" status for historical purposes. Anyway, you can set the number for a field to be 1 more than the current highest value for that field in the other records in the database by creating a sub-query in your INSERT statement INSERT INTO table_name (seqField, field1, filed2) SELECT MAX(seqField)+1, '$field1Value', '$field2Value' FROM table_name
  8. This sounds like a homework problem. If it isn't, can you state what is the business need to do as you are stating? I would not implement this as part of the Primary ID field for the table - it shouldn't be used for any functionality where it is exposed to the user. It should be transparent and just do it's thing. I would use an alternate field to store such a value. But, the solution to your problem is pretty easy, I just want to know if this is homework or not. If it is I will provide some guidance and not a specific answer.
  9. OK, are you only wanting the user to edit individual fields or the entire record? Allowing edit of the entire record would actually be easier. You could allow them to edit individual fields by clicking a button and, I assume, you want it to all happen on the current page. If that's the case, then you'll need to use a combination of JavaScript and PHP (i.e. AJAX). It would take quite a lot to explain everything, but I can break it down to the main features. 1. When generating the output, create input fields for the data - but set them to readonly and apply a style so they are visibly readonly (e.g. I typically use a grey background). So, instead of echo "<td>{$row['assignedcounselor']}</td>\n"; Use something like this echo "<td><input type='text' id='assignedcounselor' name='assignedcounselor' value='{$row['assignedcounselor']}</td>\n"; 2. Additionally, when outputting the records create an edit icon/button for each field as well as a save icon/button. These will call JS functions to initiate the edit/save processes. The function calls will need to include the field name or ID. The save option should be initially disabled. 3. Create a JS function to enable editing on a field. This will take the ID/Name passed to the function. Then it will change the style properties of the field so it is not readonly and is displayed as a normal input field. The save button should be enabled and you could also change the edit button to be a cancel button at this point. 4. Create a JS function for the save option. That function should take the ID of the field passed to reference the value in the field. It would then make an AJAX call to a PHP page to update the selected value. You would need to pass the Record ID, the name of the field and the value of the field. The response should either be a TRUE (for success) or an error message if there were validation errors. The JS function would either set the field back to the readonly state (if success) or display the error message.
  10. Use an array for the expressions and the replacements. I made some other improvements as well to account for other parameters being in the LI tags. Although it still requires that the id parameter comes before the value parameter. It could be written to work with them in any order, but I was too lazy too look up the format. $string=' <li id="5691_3" value="pass"> Some text hereA</li> <li id="5691_4" value="pass"> Some text hereB</li> <li id="5691_6"> Some text hereC</li> <li id="5691_7" value="fail"> Some text hereD</li> '; $patterns = array( '#<li.*?id="([^"]*)".*?value="pass"[^>]*>([^<]*)</li>#', '#<li.*?id="([^"]*)".*?value="fail"[^>]*>([^<]*)</li>#', '#<li.*?id="([^"]*)"[^>]*>([^<]*)</li>#' ); $replacements = array( 'Result for ID "$1" You passed! - $2<br>', 'Result for ID "$1" You failed! - $2<br>', 'Result for ID "$1" Its blank! - $2<br>' ); $string= preg_replace($patterns, $replacements, $string); echo $string; Output Result for ID "5691_3" You passed! - Some text hereA Result for ID "5691_4" You passed! - Some text hereB Result for ID "5691_6" Its blank! - Some text hereC Result for ID "5691_7" You failed! - Some text hereD
  11. You need to stop and understand what you are doing. You were informed why putting country on the URL was not being passed previously. It was because you had a FORM and you set the form method to GET - so the browser was overriding the URL parameters set in the action property with the form field data. Now, based on your last post, you are not including country in the form page at all and are apparently expecting it to be magically available on the processing page. You still never answered my questions. What is the purpose of the country value? Is it something that should persist for the user across all sessions, just the current session, or is it something that the user would need to change during a session. Only by answering those questions can we provide a good solution.
  12. Why is the data for $equipo in a subarray for the index 0? Unless there are multiple 'records' I would put the data at the root of the array array { id_equipo => "7" nom_equipo => "Vodka Juniors" locvis => "L" } But, if you want to use the current format, the use this: $newArray = $equipo; $newArray[0]['Jugadores'] = $jugador; echo "<pre>" . print_r($newArray, 1) . "</pre>";
  13. You've never shown how $country is set or how it is used. Is this something that should persist for the user for the entire visit? If so, save the value in the session or a cookie. If it is something they will set for some output but may change during their visit, use a hidden field to ensure it gets passed with the form data (although I would probably still use session data for it).
  14. Also, looking at this, it appears you want the country value to persist from page to page. If so, passing on the query string will add complication. It would be better to save it within the session or a cookie.
  15. What is the difference between the two you just posted?! Anyway, does this give you what you are wanting? $newArray = $equipo; $newArray['Jugadores'] = $jugador; echo "<pre>" . print_r($newArray, 1) . "</pre>"; Edit: this would be the same as you just posted where you appended $jugador to the $equipo array. So, I guess it isn't what you are looking for. But, again, you state that doesn't give you what you want and then post the same thing as what you do want. I'm confused.
  16. You should update your database to have a column without the letter. I would think you would want one column for the "code" and a separate one for the letter. Also, your query seems to have some inefficiencies. I don't see why you need the WHERE clause and the HAVING clause. Plus, the HAVING clause is using a separate calculation rather than the one that is included in the SELECT field list. Using Zane's example, I would think the query would look like this SELECT substring(invW.StockCode, 1, (len(invW.StockCode) - 1)) as sStockCode, SUM(invW.QtyOnHand - invW.QtyAllocated) AS 'Value' FROM SysproCompanyJ.dbo.InvWarehouse as invW WHERE Warehouse = 'SW' GROUP BY substring(invW.StockCode, 1, (len(invW.StockCode) - 1)) HAVING Value > 0 But again, I think it would be best to update the table structure.
  17. I'd also add that there is an old axiom that is mostly true. It takes 10% of the work to get 90% done and another 90% of the work to complete the last 10%. It's easy to build something brand new that does "X". But, then when you add a new requirement to do "Y" it takes a lot more effort since you have to go back and refactor the original code.
  18. Why do you have two tables? You state one table has a column for "verified" with a 1 or 0. Why not just use the records in that table and change that value (you'd probably just need to move the hash column there as well)? Seems like you're making this harder than it should be. But, I'm betting the problem is what WebStyles stated - the variable $Username is not set. It's always a good idea to create your queries as string variables so you can verify them if needed. $SQL_REQUEST = "SELECT * FROM `unverified` WHERE `Hash`='$Hash'"; $SQL_RESULT = mysqli_query($DB_CON, $SQL_REQUEST); $SQL_VALID = mysqli_num_rows($SQL_RESULT); if($SQL_VALID > 0){ $query = "UPDATE users SET Verified=1 WHERE Username='$USERNAME'"; echo $query; // Verify the query mysqli_query($DB_CON,$query); mysqli_query($DB_CON,"DELETE FROM `unverified` WHERE `Hash`='$Hash'"); echo '<p>Your account has been activated, you can now login <a href="https://www.site.org/login/">here</a></p>'; mysqli_close($DB_CON); exit(); } else{ die("The hash and/or username you provided was incorrect. If you believe this is an error, please contact customer support."); }
  19. I would not add a folder for each user. Just store the images in a single folder - or is different folders by type. You will want to ensure the files have a unique name - then add a reference to them in the database. As for your code - it needs some help. I see many problems. For example you are using strip_tags() on the password. Why? It will be hashed before putting into the database. By doing that you would be reducing the security. A user might enter "<mypassword>" as their password and you would be reducing their password to an empty string! Plus, what is the need to strip_tags() on any of the values? You should be using htmlentities() (or the other function to escape content for HTML) when outputting any user submitted data to the page. Besides, you would be changing the value the user entered without them knowing. If you were to change the value of the username - the user would not be able to log in! If you don't want to allow html code in the values, then make those validation errors. Never change the value without the user knowing. The one exception is to trim() values. Here is a quick and dirty rewrite. I didn't test it so there may be a few typos <?php if(isset($_POST['submit'])) { //Create array to hold validation errors $errors = array(); //Parse form data $fullname = trim($_POST['fullname']); $username = trim($_POST['username']); //Do NOT modify the password $password = $_POST['password']; $confirmpassword = $_POST['confirmpassword']; //Perform Non DB validations first if($fullname=='' || $username=='' || $password=='' || $confirmpassword=='') { $errors[] = "All fields are required."; } else { //Validate username content if (strlen($username)>25) { $errors[] = "Username cannot be longer than 25 characters."; } if ($username != strip_tags($username)) { $errors[] = "Username cannot contain HTML code"; } //Validate fullname content if (strlen($fullname)>25) { $errors[] = "Fullname cannot be longer than 25 characters."; } if ($fullname != strip_tags($fullname)) { $errors[] = "Fullname cannot contain HTML code"; } //Validate password content if (strlen($password)>25||strlen($password)<6) { $errors[] = "Your password must be between 6 and 25 characters."; } elseif($password==$confirmpassword) { $errors[] = "Your password and confiormation do not match."; } } //If no content errors do DB validations if(!count($errors)) { //connect to database $connect = mysql_connect("XXXX", "XXXX", "XXXX"); mysql_select_db("XXXX"); //Verify username uniqueness $query = "SELECT username FROM user WHERE username='$username'"; $result = mysql_query($query); if(!$result) { $errors[] = "Error checking username."; } elseif (mysql_num_rows($result)) { $errors[] = "Username is already taken."; } else { //Attempt to register user // encrypt password ## You should really have a better hashing method!!! $passwordSQL = md5($password); $query = "INSERT INTO user VALUES(NULL, '$fullname', '$username', '$password', NOW())": $result = mysql_query($query); if(!$result) { $errors[] = "Error checking username."; } } } if(!count($errors)) { //This should really be replaced with a redirect to a fully built confirmation page die("You've successfully registered! <a href='index.php'>Click here to return to the login page!</a>"); } //There were errors - display them $errorMessage = "The following errors occured:<ul>\n"; foreach($errors as $err) { $errorMessage .= "<li>{$err}</li>\n"; } $errorMessage .= "</ul>\n"; } ?> <html> <head> <meta charset="UTF-8"> <title>My Web Page</title> <link rel="stylesheet" href="style/style.css"> </head> <?php include_once("templates/template_pageTop.php"); ?> <body> <div id="pageMiddle"> <?php echo "<h1>Sign Up</h1>"; ?> <p> <?php if(isset($errorMessage)) { echo $errorMessage; } ?> <form action='register.php' method='POST'> <table> <tr> <td>Full Name:</td> <td><input type='text' name='fullname' value='<?php if(isset($fullname) { echo $fullname; } ?>'></td> </tr> <tr> <td>Username:</td> <td><input type='text' name='username' value='<?php if(isset($username) { echo $username; } ?>'></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'></td> </tr> <tr> <td>Confirm Password:</td> <td><input type='password' name='confirmpassword'></td> </tr> </table> <input type='submit' name='submit' value='Create Account'> </form> </p> </div> <?php include_once("templates/template_pageBottom.php"); ?> </body> </html>
  20. That's the problem. There is no need to process the begin and end dates into an array of all the days - just to find out if a certain date is included in them. You can do that very simply with a single query. $targetDate = '2014-03-05'; //Find all records where $targetDate is contained in the //period from startDate to finishDate $query = "SELECT id FROM some_table WHERE '$targetDate' BETWEEN startDate AND finishDate Don't explode the startDate and finishDate into individual days for the purpose of performing any logic on them. There are way better ways to do that programatically. Only extract into the individual days when generating the output.
  21. If this is in a database, why are you putting this logic in the PHP code? And, why would you put multiple values into a single string like that. Makes it difficult to manipulate data - as you are now finding. I'm having trouble following your logic, but it seems you are creating an array of all dates between the start date and the end date. I hope you are storing the values as actual dates and not strings. Anyway, I would create the array with just two values for the start date and the finish date. Then create logic to see if the date you are testing is between those two dates. I would not run a process to determine each day in the range until you need to output them. The logic, as it is now won't work across months. E.g. When it comes to the date March 31 it will be 0331. Then when you add 1 it will be 0332 - an invalid date.
  22. If you have the array built correctly (as I showed), this should work function subarray_search($array, $searchValue) { foreach($array as $parentKey => $subarray) { if(in_array($searchValue, $subarray)) { //If found, return parent key return $parentKey; } } //Not found, return false return false; } //Usage $key = subarray_search($array, 0304); //Note: Be sure to EXPLICITLY test for FALSE // an index of 0 can be interpreted as // false if not compared correctly if($key === false) //Note three equal signs { echo "The Value was not found"; } else { echo "The value was found in key {$key}"; }
  23. Your array doesn't make sense. If you have posted it correctly, the sub-arrays contain one element that consists of a single value. And that value is a comma separated string? If that is the case you don't need a multi-dimensional array. Although, what you should have is a multi-dimensional array with multiple elements in the sub array, such as this: Array ( [0] => Array ( [0] => 0219, [1] => 0220, [2] => 0221, [3] => 0222, [4] => 0223 ) [1] => Array ( [0] => 0301, [1] => 0302, [2] => 0303, [3] => 0304 ) [2] => Array ( [0] => 1230, [1] => 1231, [2] => 0101, [3] => 0102 ) ) So, please verify what you have
  24. 1. Don't put numeric IDs in quotes 2. Use JOINs $order_id = intval($order_id); $sql = "SELECT OP.order_product_id, OP.order_id, OP.product_id, OP.name, OP.model, OP.price, OP.total, OP.tax, OP.quantity, OP.subtract, P.weight FROM dmc9strorder_product OP JOIN dmc9strproduct P ON OP.product_id = P.product_id WHERE OP.order_id = $order_id"; $query = $this->db->query($sql);
  25. Not with the code he posted. He first checks if the quantity is 1 or less. If so, he removed the item. So, in the else condition, he is guaranteed that the quantity is 2 or greater. Thus, it would never be 0 when reduced by 1. But, on general principal I agree that your version is better. Less branching logic results in cleaner code.
×
×
  • 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.