Jump to content

Only Inserting into one table


Xtremer360

Recommended 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?

 

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 ();
    
    }  

 

Link to comment
Share on other sites

You must call mysql_query() after setting $query each time.  So it will be like

 

1.  $query = ...

2.  mysql_query($query)

3.  $query = ...

4.  mysql_query($query)

 

It's possible to run two queries in a single call, but not recommended as it makes it difficult to handle errors.

Link to comment
Share on other sites

Nope.  You must make two separate calls.

 

Your error handling should report a different message if the first call fails to if the second call fails, so you can fix the problem more easily.  You don't have to report a different message to the user, but you should at least notify yourself of where the failure happened.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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