Welcome to WebmasterWorld Guest from 54.196.244.45

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Need Help With Some MySQL Coding

     
11:23 pm on Jun 14, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 14, 2004
posts:1043
votes: 0


Hello everyone,
I have little knowledge of MySQL, and am hoping someone can help me out with a question I have. I have some code that automatically installs a table into a MySQL database. This is for a forum software modification. Here is the code:
<?php

require "./global.php";

if($mybb['uid'] == 0)
{
nopermission();
}

$sql = "CREATE TABLE `".TABLE_PREFIX."whatever` (
`did` smallint(6) NOT NULL auto_increment,
`cid` smallint(6) NOT NULL default '0',
`uid` smallint(6) NOT NULL default '0',
`name` varchar(32) NOT NULL default '',
`description` text NOT NULL,
`url` varchar(200) NOT NULL default '',
`visible` char(3) NOT NULL default '',
`sticky` char(3) NOT NULL default '',
`validated` char(3) NOT NULL default '',
PRIMARY KEY (`did`)
) TYPE=MyISAM AUTO_INCREMENT=1;";

$query = $db->query($sql);
echo "<font face=\"arial\" size=\"2\" color=\"green\"><b>Table Added:</b> forumlinks</font><br />\n";

echo "<br />\n<br />\n";
echo "<font face=\"arial\" size=\"2\" color=\"green\"><b>Installation Complete!</b><br />Please delete this file now for security reasons.</font>\n";

?>

Notice the bold line, that basically creates the new table. Instead of this script creating a table, I would like this script to insert into the specified table that already exists (my example is "whatever"). What can I change in this script to make it insert sql into a pre-existing table? Thanks!

12:21 am on June 15, 2005 (gmt 0)

Junior Member

joined:Apr 27, 2003
posts:131
votes: 0



So you want to modify this script so it changes your existing table to have these new fields?

Does this table already have data in it?

7:14 pm on June 15, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 14, 2004
posts:1043
votes: 0


Yes it does.
11:13 pm on June 15, 2005 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


So you want to ALTER [dev.mysql.com] the table?
11:43 pm on June 15, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 14, 2004
posts:1043
votes: 0


That's exactly what I was looking for. Thank you very much!