Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Multiple insert tag

    What I want to do is make another insert tag to table called bios with some things put into it but don't know how to make a multiple insert.

    PHP Code:
    if ( isset ( $_POST['addcharacter'] ) ) {
            
    // Define the query.
            
    $charactername $_POST ['charactername'];
            
    $username $_POST ['username'];
            
    $posername $_POST ['posername'];
            
    $style $_POST ['style'];
            
    $gender $_POST ['gender'];
            
    $status $_POST ['status'];
            
    $division $_POST ['division'];
            
    $alignment $_POST ['alignment'];
            
    $sort $_POST ['sort'];
            
    $query "INSERT INTO `characters` (`charactername`,`username`, `posername`, `style`, `gender`, `status`, `division`, `alignment`, `sort`) VALUES ('".addslashes($charactername)."', '".addslashes($username)."', '".addslashes($posername)."','".addslashes($style)."', '".addslashes($gender)."', '".addslashes($status)."', '".addslashes($division)."', '".addslashes($alignment)."', '".addslashes($sort)."')";
            
            
    // Execute the query.
            
    if (@mysql_query $query)) {
                print 
    '<p>The character has been added.</p>';
            } else {
                print 
    '<p>Could not add the character because: <b>" . mysql_error() . "</b>. The query was $query.</p>';
            }
            
            
    //mysql_close ();
        
        

    Last edited by CoolAsCarlito; 02-11-2009 at 03:39 AM.

  • #2
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Okay I have this and submitted the form again and now it only inserts it into the bios table. Why doesn't it also insert into the characters table?

    PHP Code:
    if ( isset ( $_POST['addcharacter'] ) ) {
            
    // Define the query.
            
    $charactername $_POST ['charactername'];
            
    $username $_POST ['username'];
            
    $posername $_POST ['posername'];
            
    $style $_POST ['style'];
            
    $gender $_POST ['gender'];
            
    $status $_POST ['status'];
            
    $division $_POST ['division'];
            
    $alignment $_POST ['alignment'];
            
    $sort $_POST ['sort'];
            
    $query "INSERT INTO `characters` (`charactername`,`username`, `posername`, `style`, `gender`, `status`, `division`, `alignment`, `sort`) VALUES ('".addslashes($charactername)."', '".addslashes($username)."', '".addslashes($posername)."','".addslashes($style)."', '".addslashes($gender)."', '".addslashes($status)."', '".addslashes($division)."', '".addslashes($alignment)."', '".addslashes($sort)."')";
            
    $query "INSERT INTO `bios` (`username`,`charactername`, `style`, `division`, `alignment`) VALUES ('".addslashes($username)."', '".addslashes($charactername)."', '".addslashes($style)."','".addslashes($division)."', '".addslashes($alignment)."')";
            
            
    // Execute the query.
            
    if (@mysql_query $query)) {
                print 
    '<p>The character has been added.</p>';
            } else {
                print 
    '<p>Could not add the character because: <b>" . mysql_error() . "</b>. The query was $query.</p>';
            }
            
            
    //mysql_close ();
        
        


  • #3
    Regular Coder lokeshshettyk's Avatar
    Join Date
    Aug 2008
    Location
    On the way to the moon!
    Posts
    157
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Try this

    PHP Code:
    <?
    if ( isset ( $_POST['addcharacter'] ) ) {
            
    // Define the query.
            
    $charactername $_POST ['charactername'];
            
    $username $_POST ['username'];
            
    $posername $_POST ['posername'];
            
    $style $_POST ['style'];
            
    $gender $_POST ['gender'];
            
    $status $_POST ['status'];
            
    $division $_POST ['division'];
            
    $alignment $_POST ['alignment'];
            
    $sort $_POST ['sort'];
            
    $query_char "INSERT INTO `characters` (`charactername`,`username`, `posername`, `style`, `gender`, `status`, `division`, `alignment`, `sort`) 
                      VALUES ('"
    .addslashes($charactername)."', '".addslashes($username)."', '".addslashes($posername)."','".addslashes($style)."', '".addslashes($gender)."', '".addslashes($status)."', '".addslashes($division)."', '".addslashes($alignment)."', '".addslashes($sort)."')";
                      
            
    $query_bios "INSERT INTO `bios` (`username`,`charactername`, `style`, `division`, `alignment`) 
                      VALUES ('"
    .addslashes($username)."', '".addslashes($charactername)."', '".addslashes($style)."','".addslashes($division)."', '".addslashes($alignment)."')";
            
            
    // Execute the query.
            
    $q1 mysql_query ($query_char) or die ("Char Query Error : " mysql_error());
            if (
    mysql_affected_rows()) {
                print 
    "Data added to char";
            } else {
                print 
    "Error";
            }
            
            
    $q2 mysql_query ($query_bios) or die ("Bios Query Error : " mysql_error());

            if (
    mysql_affected_rows()) {
                print 
    "Data added to bios";
            } else {
                print 
    "Error";
            }

            
    mysql_close ();
        
        }
    ?>
    _______________________________________________________________________________________
    Thank the user for his/her helpful post by clicking on the button below the post :)

    Cheers :)
    ~ LSK ~

  • Users who have thanked lokeshshettyk for this post:

    CoolAsCarlito (02-10-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •