I am unclear how to apply one function to another here.
I tried it in the switch with no results.
Also tried it directly in the other functions but I am just not getting it.
I have my ucfirst function
function change_tag($tag)
{
return ucfirst(strtolower($tag));
}
//print change_tag('HMM.');
switch
case "create":
if (is_jpeg($_FILES['photo']['type']['file'])
and is_valid_file_size($_FILES['photo']['size']['file'])
)
{
if(is_fields_filled_out($_POST['photo']))
{
$_POST['photo']['theme_id'] = $this_weeks_theme['id'];
$photo_id = create_photo($_POST['photo']);
copy($_FILES['photo']['tmp_name']['file'], './photos/original/'.$photo_id.'.jpg');
$notice = "Created photo";
}
break;
}
and I want to use change_tag with these functions
function create_photo($params)
{
db_connect();
$query = sprintf("INSERT INTO photos set
photos.title = '%s',
photos.email = '%s',
photos.discuss_url = '%s',
photos.theme_id = '%s',
photos.fullname = '%s',
created_at = NOW()",
mysql_real_escape_string($params['title']),
mysql_real_escape_string($params['email']),
mysql_real_escape_string($params['discuss_url']),
mysql_real_escape_string($params['theme_id']),
mysql_real_escape_string($params['fullname'])
);
$result = mysql_query($query);
if(!$result)
{
return false;
}
$photo_id = mysql_insert_id();
create_photo_tags($params['tags'], $photo_id);
return $photo_id;
}
/**
* creates our tags for our photos
* @param string $tag_str
* @param int $id
* @return bool
*/
function create_photo_tags($tag_str, $id)
{
db_connect();
$tags = explode(',', $tag_str);
foreach($tags as $tag)
{
$not_empty = trim($tag);
if(!empty($not_empty))
{
$query = sprintf("SELECT id from tags WHERE name = '%s'",
mysql_real_escape_string(strip_tags(trim($tag)))
);
$result = mysql_query($query);
if(!$result)
{
false;
}
$num_rows = mysql_num_rows($result);
if($num_rows > 0)
{
$tag_id = mysql_result($result, 0, 'id');
}
else
{
$query = sprintf("INSERT into tags set name = '%s'",
mysql_real_escape_string(strip_tags(trim($tag)))
);
$result = mysql_query($query);
if(!$result)
{
false;
}
$tag_id = mysql_insert_id();
}
$query = sprintf("INSERT into taggings set photo_id = '%s', tag_id = '%s'",
mysql_real_escape_string($id),
mysql_real_escape_string($tag_id)
);
$result = mysql_query($query);
}
}
return true;
}