Help with php/mysql if tag already exist

Discussion in 'PHP' started by DjZoC, Jun 12, 2010.

  1. #1
    hello there, hope someone can help me with this ...

    <?php
     $dbtable  = 'atx_tags';
    
     $db_conn  = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
     $db_found = mysql_select_db($dbname);
    
     if(isset($_POST['submit'])){
      $Tag       = $_POST['Tag'];
      $Date      = date('Y-m-d');
    
      $query = "INSERT INTO " . $dbtable . " (Tag,Date) VALUES ('$Tag','$Date')";
      mysql_query($query);
    
     }
    
    ?>
    
    <form action="" method="post">
     <input name="Tag" class="input" type="text"><br>
     <input type="submit" name="submit" class="input2" value="Submit">
    </form>
    PHP:
    how i can make if Tag is already added on atx_tags to dont add again and to show echo error video already added ! ... hope someone can help me with this ...
     
    DjZoC, Jun 12, 2010 IP
  2. Scripts man

    Scripts man Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    make select query
    if now exist just insert
     
    Scripts man, Jun 12, 2010 IP
  3. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    can you give me the full command please ... im kinda noob with this ...
     
    DjZoC, Jun 12, 2010 IP
  4. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    can someone help me ? thanks
     
    DjZoC, Jun 13, 2010 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #5
    It will be something like this: Not tested though

    
    <?php
     $dbtable  = 'atx_tags';
    
     $db_conn  = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
     $db_found = mysql_select_db($dbname);
    
     if(isset($_POST['submit'])){
      $Tag       = $_POST['Tag'];
      $Date      = date('Y-m-d');
     }
    
    $result = mysql_query("SELECT Tag FROM " . $dbtable . " WHERE Tag='$Tag';") or die(mysql_error());
    if(mysql_num_rows($result) == 0) {
          $query = "INSERT INTO " . $dbtable . " (Tag,Date) VALUES ('$Tag','$Date')";
          mysql_query($query);
        } else {
        echo "Tag already exist, please try again";
     }
    
    ?>
    
    PHP:
     
    MyVodaFone, Jun 13, 2010 IP
  6. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    works thank you !!! you save my day !!!
     
    DjZoC, Jun 14, 2010 IP