By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,453 Members | 3,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,453 IT Pros & Developers. It's quick & easy.

[SOLVED] Error code 1050: Table 'registration' already exists

P: 37
Trying to create a table and insert records from a webform and I keep getting this message:

"Successfully created the registration table.

Unable to execute the query.

Error code 1050: Table 'registration' already exists"

Then after the table is created I re-run the query/webform and I don't receive the error message, but it doesn't update my table?
When I go to mySQL it shows the table 'registration' but has no updated records.
I'm 99.9% positive my code is correct, but I've also been working on this for the past 4hrs, so I could be a little out of it
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $DiverID = $_GET['diverID'];
  3. if (empty($DiverID))
  4.     exit("<p>You must enter a diver ID!  Click your browser's Back button to return to     
  5.  
  6. the previous page.</p>");
  7.  
  8. $DBConnect = mysqli_connect("localhost", "root", "password")
  9.     Or die("Unable to connect to the database server.</p>"
  10.     ."<p>Error code " . mysqli_connect_errno()
  11.     . ": " . mysqli_connect_error()) . "</p>";
  12. $DBName = "scuba_school";
  13. @mysqli_select_db($DBConnect, $DBName)
  14.     Or die("<p>Unable to select the database.</p>"
  15.     . "<p>Error code " . mysqli_errno($DBConnect)
  16.     . ": " . mysqli_error($DBConnect)) . "</p>";
  17.  
  18.  
  19. $TableName = "registration";
  20. $SQLstring = "SELECT * FROM $TableName";
  21. $QueryResult = @mysqli_query($DBConnect, $SQLstring);
  22. if (!$QueryResult) {
  23.     $SQLstring = "CREATE TABLE registration (diverID SMALLINT, class VARCHAR(40), days VARCHAR(40), time VARCHAR(40))";
  24.     $QueryResult = @mysqli_query($DBConnect, $SQLstring)
  25.         Or die("<p>Unable to create the registration table.</p>"
  26.         . "<p>Error code " . mysqli_errno($DBConnect)
  27.         . ": " .mysqli_error($DBConnect)) . "</p>";
  28.     echo "<p>Successfully created the registration table.</p>";
  29.            }
  30.  
  31. $Class = $_GET['class'];
  32. $Days = $_GET['days'];
  33. $Time = $_GET['time'];
  34. $SQlstring = "INSERT INTO $TableName VALUES('$DiverID', '$Class', '$Days', '$Time')";
  35. $QueryResult = @mysqli_query($DBConnect, $SQLstring)
  36.     Or die("<p>Unable to execute the query.</p>"
  37.     . "<p>Error code " . mysqli_errno($DBConnect)
  38.     . ": " .mysqli_error($DBConnect)) . "</p>";
  39.  
  40. mysqli_close($DBConnect);
Oct 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: 37
Ok, well sometimes i guess a little sleep is needed to solve a problem. My variables were not the same in two sections of my script. User error, please ignore.. : )
Oct 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.