PHP is putting random strings into sql

I have spent all day trying to figure this out and I can't. I've literally tried everything(hence why the code is so dirty right now) to figure out why is the cause. This inserts into a SQL database but it's acting like it is counting the function and adding that to the beginning of the statement. here's my code

function countLoc($artist,$title,$title_number) {
$fileURL = get_bloginfo('url') . "/music/samples/" . $title_number . "/" . $artist . "/" . $title . "/" ;
$artistURL = rawurlencode($artist);
$titleURL = rawurlencode($title);
if ($handle = opendir("../music/samples/" . $title_number . "/" . $artist . "/" . $title )) {
    $dir = new DirectoryIterator('../music/samples/' . $title_number . "/" . $artist . "/" . $title );
    foreach($dir as $file ){ $y += ($file->isFile()) ? 1 : 0;};
    echo "a:".$y.":{i:0;";

    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != ".." ) {
            $baseURL = get_bloginfo('url') . "/music/samples/" . $title_number . "/" . $artistURL . "/" . $titleURL . "/" ;
            $fileURL = $baseURL . $entry;
            $trimmed = trim($entry, ".mp3");    
            $entry = rawurlencode($entry);
            $newBase = $baseURL . $entry;
            if (isset($x)){
                echo "i:" . $x . ";";
            $countentry = strlen($trimmed);
            $countartist = strlen($artist); 
            $newBase = strlen($newBase);
            echo "a:3:{s:24:\"releasetrack_track_title\";s:". $countentry .":\"". $trimmed ."\";s:24:\"releasetrack_artist_name\";s:". $countartist .":\"". $artist ."\";s:21:\"releasetrack_mp3_demo\";s:". $newBase .":\"". $baseURL . $entry ."\";}";
    echo "}";
    } else {
      echo ""; 

The value in SQL comes to be wrapped in what appears to be a count of the number of characters in the full function - almost as if the whole thing was wrapped in strlen and I can't for the life of me figure out why(see below).

s:1001"rest of the echo";

If I completely do away it the dir count then the strlen wrap is gone. Can anyone shed somelight?


My whole issue with this was something with the WP Import plugin. I updated it and it works perfectly fine now. Thanks guys for your help.

Need Your Help

Local JacORB call: org.omg.CORBA.OBJECT_NOT_EXIST

java jboss5.x corba jacorb

We use JacORB 2.3.0 with Java 6 and JBoss 5.1.0 in a legacy project. The CORBA infrastructure and the old versions of the ORB, Java and JBoss are given and not a subject of change.

How can a convex polygon be broken down into right triangles aligned on the X- and Y- axes?

math graphics geometry polygons

Given a convex polygon represented by a set of vertices (we can assume they're in counter-clockwise order), how can this polygon be broken down into a set of right triangles whose legs are aligned ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.