Xtremer360 Posted February 10, 2009 Share Posted February 10, 2009 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 More sharing options...
btherl Posted February 10, 2009 Share Posted February 10, 2009 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 https://forums.phpfreaks.com/topic/144566-only-inserting-into-one-table/#findComment-758687 Share on other sites More sharing options...
Xtremer360 Posted February 10, 2009 Author Share Posted February 10, 2009 So is this legal to do? // Execute the query. if (@mysql_query ( $query) ($query2)) { print '<p>The character has been added.</p>'; Link to comment https://forums.phpfreaks.com/topic/144566-only-inserting-into-one-table/#findComment-758691 Share on other sites More sharing options...
btherl Posted February 10, 2009 Share Posted February 10, 2009 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 https://forums.phpfreaks.com/topic/144566-only-inserting-into-one-table/#findComment-758700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.