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
https://forums.phpfreaks.com/topic/144566-only-inserting-into-one-table/
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.

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.

Archived

This topic is now archived and is closed to further replies.

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