#1
  1. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jan 2004
    Location
    Budapest
    Posts
    1,703
    Rep Power
    67

    Help w/ ASP Mid Function Please


    I want to have a form such that one field would be a URL for a YouTube video, suuch as these examples:

    http://www.youtube.com/watch?v=gGqj6jKVWI0&feature=plcp

    http://www.youtube.com/watch?v=gGqj6jKVWI0

    What I am ultimately after is the code for the video, in this case gGqj6jKVWI0

    I noticed in some situations the YouTube video ends w/ what I am after and other times it adds characters after it.

    I thought I had this working at one time but I keep getting an error. Here is the code I had been using that I thought worked.

    Code:
    var1 = instr(Request("code"),"http://www.youtube.com/v/")
    var2 = instr(Request("code"),"&")
    var3 = (var2 - var1) - 25
    mySQL= "INSERT INTO `videos` ( `id`, `Title`, `Description` , `code`) VALUES (" & picid + 1 & ",'"  & replace(Request("Title"),"'","''") & "', '"  & replace(Request("Description"),"'","''") & "', '" &  mid(Request("code"),instr(Request("code"),"http://www.youtube.com/v/") + 25,var3)  & "')"
    When I run this I get an invalid use of mid error
    Today the world, tomorrow the universe...
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,448
    Rep Power
    4539
    Build your MYSQL variable in some smaller chunks, it makes it easier to debug
    Code:
    e.g.,
    mysql = "some stuff"
    mysql = mysql & "some more stuff"
    mysql = mysql & mid("more stuff", 2, 4)
    Something like this keeps the mid function isolated, and if there's a problem with the function, being isolated on one line in your code makes it much easier to find the error.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jan 2004
    Location
    Budapest
    Posts
    1,703
    Rep Power
    67
    As an afterthought I think what might be easier is this.

    First use instr to see if their is an & character. If not then simply do a replace on the string to get rid of http://....etc. leaving just the snippet of code I am after.

    If there is an & in the string, then use a string function to trim off everything from the & forward, then use the replace function again to get rid of the http://... etc.

    Make sense?



    Originally Posted by Doug G
    Build your MYSQL variable in some smaller chunks, it makes it easier to debug
    Code:
    e.g.,
    mysql = "some stuff"
    mysql = mysql & "some more stuff"
    mysql = mysql & mid("more stuff", 2, 4)
    Something like this keeps the mid function isolated, and if there's a problem with the function, being isolated on one line in your code makes it much easier to find the error.
    Today the world, tomorrow the universe...
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0
    Need to convert ASP base Function into PHP

IMN logo majestic logo threadwatch logo seochat tools logo