Ok, I'm new to php and MYSQL aswell. I have a couple programs actually that are getting this error and I don't see what could be causing this at all.
Here's the situation. I have a job interview page. The user enters the information from the candidate and submits the interview. Everything works find the FIRST time around. Database is created, table is created, ID is given to the candidate, everything works good.
When I go to enter a second interview I get this error:
Unable to execute the query.
Error code 1007: Can't create database 'jobinterview'; database exists
Here's the code that creates the database, tables etc.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Job Interview</title>
<meta http-equiv="content-type"
content="txt/html; charset=iso-8859-1" />
</head>
<body>
<?php
/* ==== Code to ensure interviewer fills out all required areas === */
if (empty($_GET['first_name']) ||
empty($_GET['last_name']) ||
empty($_GET['position']) ||
empty($_GET['cand_first']) ||
empty($_GET['cand_last']) ||
empty($_GET['cand_ID']) ||
empty($_GET['comments']))
die("<p>You must enter a value in every field for the interview! Click your
browser's Back button to return to the Interview form.</p>");
if (($_GET['month'] == "Month") ||
($_GET['date'] == "Day") ||
($_GET['year'] == "Year"))
die ("<p>You must enter the full date in the drop down menus! Click
your browser's Back button to return to the Interview form.</p>");
if ($_GET['recommendation'] == "--- --- ---")
die ("<p>You must enter a recommendation value in the drop down menu! Click
your browser's Back button to return to the Interview form.</p>");
if (($_GET['intellect'] == "--- --- ---") ||
($_GET['communication'] == "--- --- ---") ||
($_GET['business'] == "--- --- ---") ||
($_GET['computer'] == "--- --- ---"))
die ("<p>You must enter values for all of the Candidate's skills/presentation
from the drop down menues! Click your browser's Back button to return to
the Interview form.</p>");
/* ==== Code to connect to the database ==== */
$DBConnect = @mysqli_connect("localhost", "user", "password")
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
/* ==== Code to create hit_counter database if it does not already exist ==== */
$DBName = "jobinterview";
if (!@mysqli_select_db($DBConnect, $DBname)) {
$SQLstring = "CREATE DATABASE $DBName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully created the database</p>";
mysqli_select_db($DBConnect, $DBName);
}
/* ==== Code to create the table and give each candidate a candID === */
$TableName = "candidates";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
if (!$QueryResult) {
$SQLstring = "CREATE TABLE $TableName (candID SMALLINT
NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(40), last_name VARCHAR(40),
position VARCHAR(40), month VARCHAR(9), date VARCHAR(2), year VARCHAR(4),
cand_first VARCHAR(40), cand_last VARCHAR(40), cand_ID VARCHAR(40), recommendation VARCHAR(20),
comments VARCHAR(350), intellect VARCHAR(20), communication VARCHAR(20), business VARCHAR(20),
computer VARCHAR(20))";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to create the table.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>Successfully created the candidates table</p>";
}
/* ==== Adds the candidate to the database and closes the connection ==== */
$Int_Last = addslashes($_GET['first_name']);
$Int_First = addslashes($_GET['last_name']);
$Int_Position = addslashes($_GET['position']);
$Month = addslashes($_GET['month']);
$Day = addslashes($_GET['date']);
$Year = addslashes($_GET['year']);
$Cand_First = addslashes($_GET['cand_first']);
$Cand_Last = addslashes($_GET['cand_last']);
$Cand_ID = addslashes($_GET['cand_ID']);
$Recommend = addslashes($_GET['recommendation']);
$Comments = addslashes($_GET['comments']);
$Intellect = addslashes($_GET['intellect']);
$Communication = addslashes($_GET['communication']);
$Business = addslashes($_GET['business']);
$Computer = addslashes($_GET['computer']);
$SQLstring = "INSERT INTO $TableName VALUES(NULL, '$Int_Last',
'$Int_First', '$Int_Position', '$Month', '$Day', '$Year', '$Cand_First', '$Cand_Last',
'$Cand_ID', '$Recommend', '$Comments', '$Intellect', '$Communication', '$Business', '$Computer')";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<strong>Interview Saved</strong>";
$CandID = mysqli_insert_id($DBConnect);
echo "<p>This candidate has been assigned an ID of $CandID.</p>";
mysqli_close($DBConnect);
?>
<hr>
<p><a href="JobInterview.html">Return to Job Interview Page</a></p>
</body>
</html>
I know it may seem a bit messy towards the end, still working on getting it tightened up and buttoned up a bit, but I'm at my wits end with this error and have looked through book after book, and searched the web and can't find a solution. Thanks for the help.
I'm currently using WAMP and have ran it through phpMyAdmin as well as trying to run it through SQLyog, same results. If that helps at all. Also, replaced my user name and password with "user" and "password" just in case.