INSERT not working
Posted: Mon Feb 23, 2009 11:39 am
Here's the code:
Here's the problem:
I can't seem to get $seasonName to insert into the database. I can hard code a value, such as:
But it doesn't work with the variable. Any thoughts?
Code: Select all
class Schedule{
public function createSeason($seasonName) {
echo $seasonName;
//Get all season names from database
$query = 'SELECT seasonName FROM season';
$result = mysql_query($query);
//Loop to see if it's already in use
$found = 0;
while ($row = mysql_fetch_array($result)) {
//If match is found, set $found = 1
if($row['SeasonName'] == $seasonName){
$found = 1;
}
}
//If $seasonName isn't already in use
if($found == 0){
//Add to database
echo $seasonName;
$query = "INSERT INTO season (SeasonName) VALUES ('$seasonName')";
if(mysql_query($query)){
echo "Worked.";
}else{
echo "Didn't work.";
}
}else{
//Else return null
return null;
}
}
public function editSeason(){
}
}I can't seem to get $seasonName to insert into the database. I can hard code a value, such as:
Code: Select all
$query = "INSERT INTO season (SeasonName) VALUES ('season1')";