addyp Posted October 13, 2010 Share Posted October 13, 2010 hi guys, I just started using msql for the frist time and am having some problems, when i go to create the new table i get the error "table already exists" i have placeds an IF statment to see is the table is created and if not to make one, however it is still returning the same error, ill post the code below anyhelp would be much apricated <?php if (empty($_POST['bug_ID'])) echo "<p>You must enter a BUG ID number, No Bug Recorded</p>"; else { $bugID = addslashes($_POST['bug_ID']); $name = addslashes($_POST['bug_name']); $date = addslashes($_POST['Date']); $sDescription = addslashes($_POST['shortDiscription']); $lDescription = addslashes($_POST['Discription']); $action = addslashes($_POST['action']); } $table = " create table bugs ( ID varchar (50) not null, Name varchar (50) not null, Date varchar (50) not null, ShortDescription varchar (50) not null, LongDescription varchar (100) not null, Action varchar (100) not null, primary key (ID) )"; $conn=mysql_connect("xxxxxxxxxxx","xxxxxxxxxxx","xxxxxxxxxx"); mysql_select_db("xxxxxxx"); $sql="SELECT * FROM $table"; $result=@mysql_query($sql); umask(0007); if (!$result) { mysql_query($table) or die(mysql_error()); } if(isset($_POST['submit'])) { mysql_query("INSERT INTO bugs (ID, Name, Date, ShortDescription, LongDescription, Action) VALUES ('$bugID', '$name', '$date', '$sDescription', '$lDescription', '$action')"); } echo "table updated"; mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/215772-table-already-exists/ Share on other sites More sharing options...
Zane Posted October 13, 2010 Share Posted October 13, 2010 Read up on the MySQL manual on creating tables http://dev.mysql.com/doc/refman/5.1/en/create-table.html Take extra special notes on the "IF NOT EXISTS" part! Quote Link to comment https://forums.phpfreaks.com/topic/215772-table-already-exists/#findComment-1121742 Share on other sites More sharing options...
Pikachu2000 Posted October 13, 2010 Share Posted October 13, 2010 Go change your database password, since you've just managed to post it on teh innerwebs. Quote Link to comment https://forums.phpfreaks.com/topic/215772-table-already-exists/#findComment-1121754 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.