Click to See Complete Forum and Search --> : [RESOLVED] Doing more than one query from another database crashes the script


mitchell
02-28-2008, 06:13 PM
does anyone know , why. as i want it to do a query in another table, and theres also another query on another table:

i have :

$result = mysql_query("SELECT * FROM alliance WHERE id='" . $user['alliance'] . "'");
$row = mysql_fetch_assoc($result);

$query1 = "CREATE TABLE `{$row['alliance_name']}_question` (
`id` int(4) NOT NULL auto_increment,
`topic` varchar(255) NOT NULL default '',
`detail` longtext NOT NULL,
`name` varchar(65) NOT NULL default '',
`datetime` varchar(25) NOT NULL default '',
`view` int(4) NOT NULL default '0',
`reply` int(4) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;";

$query2 = "CREATE TABLE `{$row['alliance_name']}_answer` (
`question_id` int(4) NOT NULL default '0',
`a_id` int(4) NOT NULL default '0',
`a_name` varchar(65) NOT NULL default '',
`a_answer` longtext NOT NULL,
`a_datetime` varchar(25) NOT NULL default '',
KEY `a_id` (`a_id`)
) TYPE=MyISAM;";

and i want to add it underneath $update but it makes the script not work :

$checkname = mysql_query("SELECT alliance_name FROM alliance WHERE alliance_name='$alliance_name'");
$checkname = mysql_num_rows($checkname);
if ($checkname>0) {
echo "The clan name is already in use";
}else{
$alliance_name = htmlspecialchars($alliance_name);
$Insert = @mysql_query("insert into alliance (alliance_name,leaderid) values ('$alliance_name', '$user[id]')") or die(mysql_error());
$GetID = @mysql_fetch_array(mysql_query("select id from alliance where leaderid='$user[id]'"));
$AllianceID = $GetID["id"];
$Update = @mysql_query("update users set alliance =$AllianceID where username='$user[username]'") or die(mysql_error());
//i want it here but it doesn't work
echo "successfull";


is it because ive already selected a table

SyCo
02-28-2008, 06:28 PM
First thing I see is vars like this
$user[username]
should be
$user['username']

Echoing the queries to the screen to look for errors and run them in a terminal/ssh window.

So you're creating tables dynamically with the script? I might look into creating a QnA table manually and using it to store the alliance's id and the Qs and the As with an incrementing QnA id as well and dynamically adding the data to it. Just a thought.

SyCo
02-28-2008, 07:33 PM
You've marked the thread resolved?

Did I help you fix it? If I did ,then wouldn't it be polite to say thanks?