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 (); } Quote Link to comment 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. Quote Link to comment 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>'; Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.