Livecode Server and Repeat Scripts on Server
JOHN PATTEN
johnpatten at me.com
Thu Jul 31 22:07:19 EDT 2014
Ok, FWIW, this appears to work:
<?lc
put $_POST["username"] into tUsername
put $_POST["password"] into tPassword
put $_POST["email"] into tEmail
put url("file:users.txt") into tUserFile
repeat for number of lines in tUserFile
if item 1 of line 1 of tUserFile is tUsername then
put "Sorry, username (" && tUserName && ") has already been used. Try another."
exit repeat
else
delete line 1 of tUserFile
end if
end repeat
if the number of lines of tUserFile <1 then
--put url(“file:users.txt") into tUserFile
put return & tUsername & "," & tPassword & "," & tEmail & "," & "Button 1" --after tUserFile
end if
--open file "users.txt" for write
--write tUserFile to file "users.txt"
--close file "users.txt"
--put tUsername & "," & "Button 1"
--end AddNewPlayer
?>
Thanks for the prodding Peter :)
John Patten
SUSD
On Jul 31, 2014, at 6:50 PM, JOHN PATTEN <johnpatten at me.com> wrote:
> If I uncomment the repeat, the “Sorry, username already in use…" message does not get triggered. It just activates the script following the “else” statement when using a duplicate username.
>
> The only time it works is if it is the first username in my csv text list is entered into the field to create an account. In this case John Patten is the first user name listed in my CSV text file and when I enter it to create a new account, it tells me it is already being used.
>
> However if I put in the second, third, etc. username, it will not give me the correct message and drops down below my “else” and runs that script.
>
> I’m wondering if I should just repeat for number of lines in csv file, check line 1 username, and then delete the line, and repeat..., etc. until it goes through list with no matching username, or finds a match and reports back the duplicate username message.
>
> It seems like it should work just going through the if-then repeat loop, but if it only works with items in the first line of the csv text file, I could just make each item in my list the first line…
>
> Thank you!
>
> John Patten
> SUSD
>
> On Jul 31, 2014, at 6:21 PM, Peter W A Wood <peterwawood at gmail.com> wrote:
>
>> Do you still have the comment at the start of the exit repeat line?
>>
>>> --exit repeat
>>
>>
>> Regards
>>
>> Peter
>>
>> On 1 Aug 2014, at 09:15, JOHN PATTEN <johnpatten at me.com> wrote:
>>
>>> Oops! Yes, I had forgotten to rename that variable. That helps.
>>>
>>> However, even when it identifies a duplicate it still allows the script beyond the “else “ to execute. Plus, depending on what line the duplicate username is located in my csv file, it loops that many times.
>>>
>>> So if username “John Patten” is on the third line of my csv text file, the resulting “put” will look like the following:
>>>
>>> John Patten, password, jpatten at bmail.com, Button 1
>>> John Patten, password, jpatten at bmail.com, Button 1
>>> John Patten, password, jpatten at bmail.com, Button 1
>>> Sorry, username ( John Patten) has already been used. Try another.
>>>
>>> What I need to happen is the just the last line, otherwise it will create a new entry for an existing user.
>>>
>>> Is there a solution to this, or does LiveCode server run straight through if-then constructs?
>>>
>>> Thank you!
>>>
>>> John Patten
>>> SUSD
>>>
>>>
>>> On Jul 31, 2014, at 5:55 PM, Peter W A Wood <peterwawood at gmail.com> wrote:
>>>
>>>> To: How to use LiveCode <use-livecode at lists.runrev.com>
>>>>
>>>> There seems to be a typo in your code:
>>>>
>>>>> repeat for each line thisLine in tUserFile
>>>>>
>>>>> if item 1 of tLine is tUsername then
>>>>
>>>> I think that should be item 1 of thisLine
>>>>
>>>> Regards
>>>>
>>>> Peter
>>>>
>>>>
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> use-livecode at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>>> use-livecode at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list