...

View Full Version : Resolved Multiple insert tag



CoolAsCarlito
02-10-2009, 03:43 AM
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.


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

}

CoolAsCarlito
02-10-2009, 04:13 AM
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 ();

}

lokeshshettyk
02-10-2009, 06:06 AM
Try this



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

}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum