I am trying to add some data into my databases but only after checking to see if they exist. Here is my code.
$state_query = "select * from bowling_state where state_abbrev = ".$alley_state."";
$city_query = "select * from bowling_city where city_name = ".$alley_city."";
$zip_query = "select* from bowling_zipcode where zipcode = ".$alley_zipcode."";
// State Query
$state_result = mysql_query($state_query);
if ($state_result == FALSE)
{
$add_state_query = "INSERT INTO bowling_state {
state_abbrev}
VALUES {
'".$alley_state."'}";
$result = mysql_query($add_state_query) or die(mysql_error());
}
$state_result = mysql_query($state_query) or die(mysql_error());
$state_array = mysql_fetch_array($state_result); // Contains State Information Line
$state_id = $state_array['state_id'];
The table bowling_state exists (state_id, state_name, state_abbrev) and $alley_state is received from POST from a form. However when I run the code I get the following error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '{ state_name, state_abbrev} VALUES {
What I am trying to do:
Check to see if a state is already in the table bowling_state (will be repeating for cities and zips).
If it does not exist, add it.
Re-run query and grab the state_id to add into information on another table.
Any help is greatly appreciated.
Thanks
Shawn