Jump to content

akitchin

Staff Alumni
  • Posts

    2,515
  • Joined

  • Last visited

    Never

Posts posted by akitchin

  1. regarding the first query (to delete duplicates from table2 that exist in table1): are you certain that the "username" columns are identical? is there a spacing difference (e.g. does one consistently have a leading or trailing space)?

     

    as for the second issue of duplicates WITHIN table2, i think some example data would help here. are you saying you want to keep any rows with duplicate usernames but non-empty email fields, while setting the duplicate username values to NULL and vice versa? if so, you may want to reconsider how you've designed your table...

     

    EDIT: thanks pikachu, i (wrongly) assumed the other thread was deleted.

  2. well, the first query should be pretty simple. you can just delete from the second table where any username is in the entire first table:

     

    DELETE FROM table2 WHERE username IN (SELECT DISTINCT username FROM table1)

     

    here is a link containing some code that will help you figure out how to remove similar records (that is, records containing a duplicate value in one column):

     

    http://www.cryer.co.uk/brian/sql/sql_delete_duplicates.htm#DeleteSimilarRecords

     

    the code he gives is to delete all similar records, while retaining the one with the lowest `uniqueField`. that's something you can change as per your requirements, depending on which record you want to keep in case of duplicate values.

     

    you can run the first query, followed by the second and third in whichever order you choose to. hope this helps.

  3. my mistake - I should have looked at the HTML form. since your dropdown select box is named "category_selection", you should be able to use:

     

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission"))
    {
      switch($_POST['category_selection'])
      {
        case 'Web_sites':
          $table_name = 'partner_sites';
          break;
        case 'Blogs':
          $table_name = 'partner_blogs';
          break;
        case 'Directories':
          $table_name = 'partner_directories';
          break;
      }
      $insertSQL = sprintf("INSERT INTO `$table_name` (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['url_field'], "text"),
                           GetSQLValueString($_POST['title_field'], "text"),
                           GetSQLValueString($_POST['anchor_field'], "text"),
                           GetSQLValueString($_POST['description_field'], "text"),
                           GetSQLValueString($_POST['webmaster_nane_field'], "text"),
                           GetSQLValueString($_POST['webmaster_email_field'], "text"),
                           GetSQLValueString($_POST['category_selection'], "text"));
      mysql_select_db($database_content_conn, $content_conn);
      $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error());

  4. first off, you could save yourself a lot of space by simply switch()ing on the $site_type to change the table name, and assign a single query:

     

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission"))
    {
      switch($site_type)
      {
        case 'Web_sites':
          $table_name = 'partner_sites';
          break;
        case 'Blogs':
          $table_name = 'partner_blogs';
          break;
        case 'Directories':
          $table_name = 'partner_directories';
          break;
      }
    
        $insertSQL = sprintf("INSERT INTO `$table_name` (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)",                       GetSQLValueString($_POST['url_field'], "text"),                       GetSQLValueString($_POST['title_field'], "text"),                       GetSQLValueString($_POST['anchor_field'], "text"),                       GetSQLValueString($_POST['description_field'], "text"),                       GetSQLValueString($_POST['webmaster_nane_field'], "text"),                       GetSQLValueString($_POST['webmaster_email_field'], "text"),                       GetSQLValueString($_POST['category_selection'], "text"));
      mysql_select_db($database_content_conn, $content_conn);
      $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error());
    }

     

    second, i would guess that the issue with your code is the use of $site_type. where is this variable coming from? since you're accounting for QUERY_STRING i'd assume it's coming from the URL. if so, then you still need to access it using the $_GET superglobal.

  5. your issue is greediness. patterns are by default greedy in the PCRE functions in PHP. what this means is they will match the LARGEST POSSIBLE pattern. since you have (.+) in your pattern, that means that this whole thing:

     

    "http://images.4chan.org/adv/src/1288558759794.png blah blah http://images.4chan.org/sci/src/"

     

    will be matched, since "adv/src/1288558759794.png blah blah http://images.4chan.org/sci" matches the (.+) subpattern you have in there. use the question mark after your quantifier to make it ungreedy by default:

     

    "#http:\/\/images\.4chan\.org\/(.+?)\/src\/#s"

     

    otherwise you can use the U modifier at the end of the pattern:

     

    "#http:\/\/images\.4chan\.org\/(.+)\/src\/#sU"

     

    EDIT: AbraCadaver's post will also work.

  6. it's tough to answer your question, since we have no idea how your session is currently structured or how/where you set the original $_SESSION values. could you not simply use:

     

    $_SESSION['bio'] = $bio;

     

    to rewrite with the new $bio information? you don't necessarily have to "reset" the session, you can simply overwrite the current variables with the new information.

  7. this probably has to do with flash more than anything. $_SERVER['HTTP_REFERER'] shouldn't be relied upon, since it can be spoofed by the browser. however, can you be more precise as to what flash means by sequence error? if it means that the headers have already been sent, then it means that there is output from the PHP file before the attempted header call, which is a very common error. the problem is, without knowing what your file structure is like (ie. what gets called by what file and when), it's difficult for us to track it down for you.

  8. please use code tags in the future. also, even though your question is simple, it would be helpful to actually WRITE the question into the post, rather than just posting your code and assuming everyone knows what you want to achieve.

     

    i'm moving this to the javascript board because this is more of a javascript question. look into the "onClick" event and the "disabled" attribute of the input element.

  9. glad it helped - i didn't realize there were two spaces between each data set, i suppose the BB code might have stripped that out. i should mention that if you yourself wrote the script to write to the log file, it might be more handy to use serialize to compress the data that forms part of the error, strip that whole chunk out somehow (perhaps using a set delimiter), and use unserialize to break that data back out into variable form.

     

    then again, if this method works just fine now, no need to mess with it. just a thought for future applications.

  10. unfortunately i'm not that knowledgeable on performance issues, so i couldn't tell you off the top of my head. you could test by getting a JOIN query that works and running that against this sub-query method a few times. sub-query tutorials on the rest of the internetz might also include performance in their discussion.

     

    if fenway sees this thread i'm sure he will be able to offer an expert answer :).

  11. in that case, you might be able to use a look-ahead assertion, which allows for two cases:

     

    1. the closing single-quote in the category value subpattern must be followed by a " '" (space then single-quote) to capture all of the middle data sets, and

    2. the closing single-quote in the category value subpattern must be followed by a "." (period) to capture the last data set.

     

    give this a shot. i'll admit i haven't tested it, i simply constructed it from the PHP manual entry on Assertions (click to view):

     

    "/   '(.*?)' Merchant value: '(.*?)' catalog value: '(.*?)'(?= \'|\.)/i"

     

    there is mention of the look-behind assertion needing to match strings of the same fixed length, but i don't know if the same holds true for look-ahead assertions. hope this helps.

  12. For email addresses I would use

     

    if ( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false )
    {
       $errors[] = 'The email address you have entered is not valid.';
    }
    else
    {
       $email = $_POST['email'];
       // other stuff
    }

    filter_var

     

    You may not even require regex for the phone number format, if you only wish to restrict the length use strlen and compare it's return value to the desired length.

     

    fancy! that's what i get for not keeping up-to-date on the newest PHP5 functions.

×
×
  • 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.