Trying to create a table and insert records from a webform and I keep getting this message:
"Successful ly 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
"Successful ly 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
Code:
<?php $DiverID = $_GET['diverID']; if (empty($DiverID)) exit("<p>You must enter a diver ID! Click your browser's Back button to return to the previous page.</p>"); $DBConnect = mysqli_connect("localhost", "root", "password") Or die("Unable to connect to the database server.</p>" ."<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; $DBName = "scuba_school"; @mysqli_select_db($DBConnect, $DBName) Or die("<p>Unable to select the database.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; $TableName = "registration"; $SQLstring = "SELECT * FROM $TableName"; $QueryResult = @mysqli_query($DBConnect, $SQLstring); if (!$QueryResult) { $SQLstring = "CREATE TABLE registration (diverID SMALLINT, class VARCHAR(40), days VARCHAR(40), time VARCHAR(40))"; $QueryResult = @mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to create the registration table.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " .mysqli_error($DBConnect)) . "</p>"; echo "<p>Successfully created the registration table.</p>"; } $Class = $_GET['class']; $Days = $_GET['days']; $Time = $_GET['time']; $SQlstring = "INSERT INTO $TableName VALUES('$DiverID', '$Class', '$Days', '$Time')"; $QueryResult = @mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " .mysqli_error($DBConnect)) . "</p>"; mysqli_close($DBConnect);
Comment