PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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(){
}
}
Here's the problem:
I can't seem to get $seasonName to insert into the database. I can hard code a value, such as:
Try taking the quotation marks off the variable. Also try echoing the variable instead of doing the mysql_query to see what value the browser is holding in the variable when it tries to insert it into the query. That's what I would do.
I've tried it without the quotes, with singles quotes, concatenated with double quotes. Nothing seems to work. You can see in my code that I echo the variable a couple times and both times it outputted correctly. Do you think it matters that it's in a class? Thanks for your help!