Fork me on GitHub

Odd Problem with String only passing 1 digit  Bottom

  • I'm writing a hack of sections to create a library for my site and I ran into a weird error tonight.

    Each "creator" entry has a unique assigned to the cid column in the table and you click on that to bring up a full view of that entry

    here's the "list" view
    http://altertainment.net/Library-req-creatorsrecent.html

    and here's a full view
    http://altertainment.net/index.php?name=Library&req=creatorsview&cid=9
    (i took off short urls wondering if it was the problem but i don't think it is)

    For some reason I can't deduce, cid is only passing 1 digit in postnuke. (the column in mySQL set is "pn_cid int(11) No auto_increment")

    As my entries into the cid column went to 10, 11, 12, etc my admin.php side put in the date just fine - but on the index.php side in trying to show full view you can put in any number you want for cid in the URL, but it will only look at 1-9 (well I didn't test 0)

    so
    http://altertainment.net/index.php?name=Library&req=creatorsview&cid=955

    is the same as
    http://altertainment.net/index.php?name=Library&req=creatorsview&cid=9

    I can post code for my index.php file but is there any obvious "duh" reason for why this is happening?

    Help! :0
  • The usual cause of this is mis-using list and pnVarCleanFromInput. In many places in the code we have list ($var1, $var2, ....) = pnVarCleanFromInput('var1', 'var2') so for one variable people have list($var) = pnVarCleanFromInput('var') but this is incorrect.

    pnVarCleanFromInput only returns an array when more than one variable is passed in otherwise it returns the value of the variable. When you use list with only one variable to pnVarCleanFromInput the result is then extracted as an array - a string is an array of characters hence you get the first character your expected var.

    For a single variable use $var = pnVarCleanFromInput('var');

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Mark,

    You nailed that - I had list ( ) with the one variable (cid) and I changed it as you suggested and (KNOCK ON WOOD) it looks like it fixed it.
  • damn, this problem had been bugging me for the longest in a module i was doing a while back. glad to finally know the real reason
  • There are two reasons I know this...

    1) being familiar with the code (obviously)
    and
    2) it was one of my first mistakes when I started coding PN modules a while ago now.....

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Thanks again for the help Mark. I bet this thread will help lots of others now (I couldn't find another thread on point before I posted) avoid this mistake.
  • A search for 'pnvarcleanfrominput' and 'first character' (using search for all terms) turns up a few occasions where i've discussed this before.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • I have seen a few posts regarding the same issue (been there myself... drove me mental), it's just a hard one to search for since all the terms you would use are common to so many other problems people run into.

    --
    Under Construction!
  • I didn't search for "first character' because I didn't have a clear grasp of what my problem was when I searched. That is always the hardest thing - to figure out what is the right question you should be asking! :)
  • Absolutely - getting the search terms is always a little difficult if you don't know what the problem is.....

    However i'd suggest using the forum filter and filtering things to just the dev forum as this will substantially narrow your result set.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • i posted this problem too, but wasnt sure of what to call it.
  • Well, expect it to be part of the Knowledgebase on the new site, I've made a mental note of this one :)

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide

This list is based on users active over the last 60 minutes.