Jump to content

shanetastic

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by shanetastic

  1. I was only showing a simplified version of the page. The full version sets the action to one of multiple things based on some criteria.
  2. Solved. Changing the href to: <a href='javascript:if(OnSubmitForm())document.myform.submit()'> gets it working!
  3. I don't believe that is correct. The javascript that is called sets the action (at least it is supposed to). If I use a traditional submit button (a submit input field inside the form) it works fine.
  4. Here is the code for test.html: <html> <head><title></title></head> <body> <script type="text/javascript"> function OnSubmitForm(){ document.myform.action ="insert.html"; return true; } </script> <form name="myform" onsubmit="return OnSubmitForm()" method="get"> <input type='radio' name='Search' value='test'>test</input> </form> <a href='javascript:document.myform.submit()'><img src='images/buttonnext.jpg'></a> </body> </html> The way I want it to work: when the img (buttonnext.jpg) is clicked, the form is submitted. When the form is submitted it runs the javascript, which sets the action to be that insert.html is loaded. i.e. the end result should be to redirect to insert.html?Search=test The way that it is working now: the page is redirected to test.html?Search=test What do I need to change to accomplish my goal?
  5. $Rep = htmlspecialchars($_GET["Rep"]); echo $Rep; The above will print "John Doe & Assoc." (without the quotes) $result = mysql_query("SELECT RepName FROM Reps WHERE Repname = '".$Rep."'"); $repcount = mysql_num_rows($result); echo $repcount; The above code prints "0" If I delete the first block of code and replace it with $Rep = "John Doe & Assoc." The second block of code will then return a "1" as it should. Why is one returning a 0 and one returning a 1 when the text in $Rep appears to be identical in both cases? This problem only appears to be occurring when the $Rep value contains an &.
  6. First, thank you both for your responses. However, it turns out my original query works fine...it was more of an id10t error. I was using the "explain" button in Navicat thinking it was a trace button (I didn't want to actually run the delete until I had all the bugs worked out). I did not realize that that EXPLAIN is an actual mysql command....and that that command isn't compatible with DELETE *facepalm*
  7. I am getting this error: [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE FROM Territories USING Territories, Reps, States, Principals WHERE Terr' at line 1 When I try to run this query: DELETE FROM Territories USING Territories, Reps, States, Principals WHERE Territories.RepID = Reps.RepID AND Territories.PrincipalID = Principals.PrincipalID AND Territories.StateID = States.StateID AND Reps.RepName = 'CompanyA' AND Principals.PrincipalName = 'CompanyB' AND States.StateAbbreviation LIKE '%NC%'; What am I doing wrong Here are my table structures: Reps ------ RepID RepName Principals ----------- PrincipalID PrincipalName States -------- StateID StateAbbreviation Territories ------------ RepID PrincipalID StateID
  8. Am I getting warmer? INSERT INTO Territories (RepId, PrincipalID, StateID) JOIN StatesON Territories.StateID = States.StateID JOIN Reps ON Territories.RepID = Reps.RepID JOIN Principals ON Territories.PrincipalID = Principals.PrincipalID SELECT Reps.RepID as RepID Where Reps.RepName = 'ARepName' SELECT Principals.PrincipalID as PrincipalID Where Principals.PrincipalName = 'APrincipalName' SELECT States.StateID as StateID Where States.StateAbbreviation LIKE '%LA%'
  9. Here is my query: INSERT INTO Territories (RepId, PrincipalID, StateID) SELECT Reps.RepID Where Reps.RepName = 'ARepName' SELECT Principals.PrincipalID Where Principals.PrincipalName = 'APrincipalName' SELECT States.StateID Where States.StateAbbreviation = 'LA' I have four tables: Reps ------ RepID RepName Principals ----------- PrincipalID PrincipalName States -------- StateID StateAbbreviation Territories ------------ RepID PrincipalID StateID I know the RepName, PrincipalName, and StateAbbreviation. I am trying to use those to pull the respective IDs from the respective tables and then insert a row into Territories. What am I doing wrong?
  10. Glad I asked before I started coding some ridiculous method! So it looks like all I have to do is use action=destination.php and method=post. I thought form data had to be passed in the URL unless you used a script to do something like a was proposing. This is obviously much easier. Thanks!
  11. I have a page that has roughly 100 text input fields. Once the user is done, I need to put the data in my mysql db. How do I get the data from the user input page to the php page that will process the data (e.g. process.php)? I've done some searching and found a few possibilities [*]use a ajax style call back to load a seperate asp page (e.g. createsession.asp) and that page set session variables that can then be read by process.php [*]write everything to a cookie using some sort of a delimiter so that it can handle multiple variables (e.g. cookie data => var1/var2/var3/var4... [*]write all the data to a text file and then have process.php load that file Which should I pursue? Is there a better option?
  12. Yes, I had tried several attempts at JOINs, but I was missing the "ON" statement. Now that I have that piece of the puzzle it is working perfectly
  13. I know this is basic, but I cannot figure it out. Here are my tables: Rep ----------- RepID (PK) RepName RepURL Company ----------- CompanyID (PK) CompanyName CompanyURL CompanyDescription States ----------- StateID (PK) StateAbbreviation StateName Territory ---------- RepID (PK) CompanyID (PK)* SateID (PK)* *these two columns will be made into a unique index. I would like a query that searches the Territories table and returns States.StateAbbreviation and Company.CompanyName for a given RepName. So is the RepName = "Rep1", the query should look in the Reps table and get the corresponding RepID. Then it should return all of the rows in Territories that match that RepID. Except I would like it to look at the States and Company tables so to return the StateAbbrevation and CompanyName rather than the IDs that are used in the Territories table.
  14. I think that I am going to move forward with Gizmola's recommendation, minus the CompanyRep table (unless I figure out if it is needed). So here is what my final product will look like Rep ----------- RepID (PK) RepName RepURL Company ----------- CompanyID (PK) CompanyName CompanyURL CompanyDescription States ----------- StateID (PK) StateAbbreviation StateName Territory ---------- RepID (PK) CompanyID (PK)* SateID (PK)* *these two columns will be made into a unique index. If anyone has any feedback please let me know. Otherwise, thanks again to Gizmola!
  15. I need to create a table containing only a list of company names. Company names should not be null and should be unique. Can I just have one column (the company name) and make it the primary key? Or do I need to have two columns, an auto-incrementing int as the primary key and the company name? If it is better to have the int PK, please explain why.
  16. I believe I have found the answer to my last question (the one I referred to as a noob question). Here is a great article about design mistakes: http://www.simple-talk.com/sql/database-administration/ten-common-database-design-mistakes/. The author spends some time explaining "normalization", which answers my question. My first question, still stands though: What is the need for the CompanyRep table? Thanks again for taking the time to help a rookie out.
  17. Thanks. This is very helpful, but I hope you can add some more clarity for me. If I understand you correctly, you recommend doing this with a total of five tables: one that lists company names and company ids, one that list rep names and rep ids, one that list state names and state ids/abbreviations, the CompanyRep table that you describe and the CompanyRepState table that you describe. Is that correct? What is the need for the CompanyRep table since that same information is also going to be contained in the CompanyRepState table? Taking that a little further (and I know this is a noob question), what not have only the CompanyRepState table and populate it with the actual names instead of ids linked to other tables? For example: CompanyRepState RepName CompanyName State ----------- ---------------- ------ RepA CompanyA NC RepA CompanyA SC RepA CompanyB NC RepB CopmanyB SC
  18. I'm trying to get everything mapped out before I start writing my php code. I have three factors that I plan on storing in databases: company, rep, state. Only one rep can work with a given company in a given state. A rep can represent the same company in multiple states. For example: RepA could represent CompanyA in NC and SC. RepA could represent CompanyB in NC only. And RepB could represent CompanyB in SC only. My thought is that the best way to do this is with three types of tables: -table 1 is a list of reps -table 2 is a list of companies -then I would have a table for each state. These tables would show the relationships of reps to companies in that state. So my example would look like this: Rep Table: rep RepA RepB Company Table company CompanyA CompanyB NC Table rep company RepA CompanyA RepA CompanyB SC Table rep company RepA CompanyA RepB CompanyB Am I on the right track or is there a better way to do this? Do I need to add indexes or anything like that (sorry, I'm completely new to mysql).
  19. Thanks! The additional debugging information helped me find my mistake. I had the table name and field name switched
  20. I found an article on how to implement a mysql search (http://www.iamcal.com/publish/articles/php/search/) and it seemed like a good way to go, but I can't get it up and running. Here is my code: <?php $db_host = 'localhost'; $db_user = 'username'; $db_pwd = 'password'; $database = 'dbname'; $table = 'Principals'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $searchterms = 'dorr oliver'; function search_split_terms($terms){ $terms = preg_replace("/\"(.*?)\"/e", "search_transform_term('\$1')", $terms); $terms = preg_split("/\s+|,/", $terms); $out = array(); foreach($terms as $term){ $term = preg_replace("/\{WHITESPACE-([0-9]+)\}/e", "chr(\$1)", $term); $term = preg_replace("/\{COMMA\}/", ",", $term); $out[] = $term; } return $out; } function search_transform_term($term){ $term = preg_replace("/(\s)/e", "'{WHITESPACE-'.ord('\$1').'}'", $term); $term = preg_replace("/,/", "{COMMA}", $term); return $term; } function search_escape_rlike($string){ return preg_replace("/([.\[\]*^\$])/", '\\\$1', $string); } function search_db_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = '[[:<:]]'.AddSlashes(search_escape_rlike($term)).'[[:>:]]'; } return $out; } function search_perform($terms){ $terms = search_split_terms($terms); $terms_db = search_db_escape_terms($terms); $terms_rx = search_rx_escape_terms($terms); $parts = array(); foreach($terms_db as $term_db){ $parts[] = "Principals RLIKE '$term_db'"; } $parts = implode(' OR ', $parts); $sql = "SELECT * FROM Principal WHERE $parts"; $rows = array(); $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $row[score] = 0; foreach($terms_rx as $term_rx){ $row[score] += preg_match_all("/$term_rx/i", $row[Principals], $null); } $rows[] = $row; } uasort($rows, 'search_sort_results'); return $rows; } function search_rx_escape_terms($terms){ $out = array(); foreach($terms as $term){ $out[] = '\b'.preg_quote($term, '/').'\b'; } return $out; } function search_sort_results($a, $b){ $ax = $a[score]; $bx = $b[score]; if ($ax == $bx){ return 0; } return ($ax > $bx) ? -1 : 1; } function search_html_escape_terms($terms){ $out = array(); foreach($terms as $term){ if (preg_match("/\s|,/", $term)){ $out[] = '"'.HtmlSpecialChars($term).'"'; }else{ $out[] = HtmlSpecialChars($term); } } return $out; } function search_pretty_terms($terms_html){ if (count($terms_html) == 1){ return array_pop($terms_html); } $last = array_pop($terms_html); return implode(', ', $terms_html)." and $last"; } # # do the search here... # $results = search_perform($searchterms); $term_list = search_pretty_terms(search_html_escape_terms(search_split_terms($searchterms))); The table name is 'Principals' and the field name I am trying to search is 'Principal'. I am getting an error on the line: while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ The error is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Can anyone shed some light on this for me?
×
×
  • 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.