syntax error

    Date: 12/31/05 (PHP Community)    Keywords: php, mysql, html, sql

    Ok, I'm being slowly driven nuts by this. There is a syntax error and whatever it is, my eyes are just sliding right past it each time. If anyone can spot it I will be eternally grateful. The error is "
    Parse error: parse error, unexpected ';' in /home/remove/public_html/test/root/admin_functions.php on line 35"

    I have marked the line 35 in red.

    If anyone can think of a better way of doing this (while your here) that would be great. It takes tags much like you would set for an LJ entry, splits them up and then checks the tags table for them, if they aren’t there it then adds them. Then for each tag, it sets up a map in the maptag table which links the page_id to the tag id (the tag id in the tags table is set in an auto_increment, so it have to run yet another query to find this out).

    It doesn’t have to be too fast though, its only admin.

    function update_tags($page_id, $tags_string)
    {
    $tag_array = explode(',', $tags_string, -1);
    $count = count($tag_array);
    for ($i = 0; $i < $count; $i++)
    {
    $update_tags_query = "SELECT `id` FROM `tags` WHERE `name` = '" . $tag_array[$i] . "'";
    $update_tags_result = mysql_query($update_tags_query) or die('update tags query failed: ' . mysql_error());
    if(mysql_num_rows($update_tags_result)==0)
    {
    //add entry to tags table
    $tag_update_query = "INSERT INTO tags (name) VALUES ('" . $tag_array[$i] . "')";
    mysql_query($tag_update_query) or die('tag update query failed: ' . mysql_error());

    //then find out the new tags id
    $tags_query = "SELECT `id` FROM `tags` WHERE `name` = '" . $tag_array[$i] . "'";
    $tags_result = mysql_query($tags_query) or die('tags query failed: ' . mysql_error());
    $tags_array = mysql_fetch_array($tags_result);

    //then add to the maptag table
    $maptag_update_query = "INSERT INTO maptag (contentid, tagid) VALUES (" . $page_id . ", " . $tags_array['id'] . ")";
    mysql_query($maptag_update_query) or die ('maptag update query 1 failed: ' . mysql_error());
    }else(
    //add entries to the maptag table
    $update_tags_array = mysql_fetch_array($update_tags_result);
    $maptag_update_query = "INSERT INTO maptag (contentid, tagid) VALUES (" . $page_id . ", " . $update_tags_array['id'] . ")";
    mysql_query($maptag_update_query) or die ('maptag update query 2 failed: ' . mysql_error());
    }
    }
    }

    Source: http://www.livejournal.com/community/php/386426.html

« Selecting a random image... || I'm sure I'm... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home