Php help need !!!

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

  1. #1
    my code

    <?php
    
     if(isset($_POST['submit'])){
      $Title = $_POST['Title'];
      $Weburl = $_POST['Weburl'];
      $Category = $_POST['Category'];
      $UserIp = $_SERVER['REMOTE_ADDR'];
      $AddDate = date('Y-m-d');
    
      $Add = "1";
    
      if ($Title != "Title?" && $Title != " " && $Weburl != "http://" && $Category != "0") {
    
       $query = "INSERT INTO web_url1 (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')";
       $query = "INSERT INTO web_url2 (Weburl,UserIp) VALUES ('$Weburl', '$UserIp')";
    
       mysql_query($query);
    
       $addlink_msg = "Success! Your Video has been added!";
      } else {
       $addlink_msg = "You Mistake Someting!";
      }
     }
    
    ?>
    PHP:
    this part is not working

    
       $query = "INSERT INTO web_url1 (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')";
       $query = "INSERT INTO web_url2 (Weburl,UserIp) VALUES ('$Weburl', '$UserIp')";
    
       mysql_query($query);
    PHP:
    how i can add 2 query INSERT ? thanks for any help
     
    DjZoC, Jun 5, 2010 IP
  2. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #2
    U are modifying $query just after it is declared. In this way, the first query isnt of any use. Try this

    $query = "INSERT INTO `web_url1` (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate');";
    $another_query = "INSERT INTO `web_url2` (Weburl,UserIp) VALUES ('$Weburl', '$UserIp');";
    mysql_query($query);
    mysql_query($another_query);
    PHP:
     
    shubhamjain, Jun 5, 2010 IP
  3. elisha24

    elisha24 Well-Known Member

    Messages:
    359
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    160
    #3
    you have written in wrong manner .search on net to find correct way
    ryt is like$ querry="your query" .
    $query=$query." next query";
     
    elisha24, Jun 5, 2010 IP
  4. elisha24

    elisha24 Well-Known Member

    Messages:
    359
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    160
    #4
    may be shubhamjain is ryt for same insertion queries....mine is for broken piece query
     
    elisha24, Jun 5, 2010 IP
  5. Scripts man

    Scripts man Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Scripts man, Jun 5, 2010 IP
  6. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    i try like this

    
       $querry = "INSERT INTO " . $dbtable . " (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')";
       $query  = $query . "INSERT INTO web_url (Weburl,UserIp) VALUES ('$Add', '$UserIp')";
       mysql_query($query);
    
    PHP:
    and like this

    
       $querry = "INSERT INTO " . $dbtable . " (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')";
       $query  = $querry . "INSERT INTO web_url (Weburl,UserIp) VALUES ('$Add', '$UserIp')";
       mysql_query($query);
    
    PHP:
    the first is working just $query and the last is not working nothing ... hope someone can help me ..
     
    DjZoC, Jun 5, 2010 IP
  7. helvetica

    helvetica Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Try this one:
    <pre>
    $querry = "INSERT INTO " . $dbtable . " (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate')";
    $query = $querry . "INSERT INTO web_url (Weburl,UserIp) VALUES ('$Add', '$UserIp')";
    $first_query = mysql_query($query);
    if($first_query == 1)
    {
    mysql_query($querry);
    }
    </pre>
     
    helvetica, Jun 5, 2010 IP
  8. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    works ! thank you !!!!!
     
    DjZoC, Jun 5, 2010 IP
  9. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #9
    use shubhamjain's
    
    $query = "INSERT INTO `web_url1` (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate');";
    $another_query = "INSERT INTO `web_url2` (Weburl,UserIp) VALUES ('$Weburl', '$UserIp');";
    mysql_query($query);
    mysql_query($another_query);
    
    PHP:
    or this

    
    $query = "INSERT INTO `web_url1` (Title,Weburl,Category,UserIp,AddDate) VALUES ('$Title', '$Weburl', '$Category', '$UserIp', '$AddDate');";
    mysql_query($query);
    
    $query = "INSERT INTO `web_url2` (Weburl,UserIp) VALUES ('$Weburl', '$UserIp');";
    mysql_query($query);
    
    PHP:
     
    gapz101, Jun 5, 2010 IP
  10. helvetica

    helvetica Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Try to change the condition to
     
    helvetica, Jun 5, 2010 IP
  11. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #11
    check if this won't create duplicates
     
    gapz101, Jun 5, 2010 IP
  12. qrpike

    qrpike Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Also just a FYI for future refrences, be careful when using a ' or a ", the ' does not look for variables inside of it (use this when you dont have any variables in the string, like an echo to speed up your scripts slightly).
     
    qrpike, Jun 6, 2010 IP