| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
Join Date: Feb 2007
Posts: 31
|
Strange Code
Okay, lets see how non complicated I can make this sound. This relates to another type that I asked here. I would link you but it wouldnt let me, also I couldnt link my pictures, sorry if they are small Below is a function that I use to edit information in my database. $id is the primary key of the row in the database I want to edit. $data is the html that is used to display things properly on page (template for the editHack page). How I have this system setup is so that someone can post a "hack", aka tutorial on my webpage. This would be rather simple but I have made it so they can upload pictures specific to this hack. Now when they go to edit the hack I want all the pictures that are related to the hack to be placed back into a table so I can use AJAX to extract it and put them into a drop down menu (I use AJAX so they don't have to refresh the page when they upload an image, it simples just updates the drop down menu with the new image). Now on to what a major part of this code does. Like the thread I referenced above, I am using a system that will insert variables into a html template. Thats for the most part what this code does. It takes the html template searches it for a specific pattern, and then inserts information where the pattern matches. So my problem isn't so much the functioning of this script. It works fine for the most part. My problem comes when I have a specific set of code in my html template. If I have textarea tags ANYWHERE in the html template I encounter an "error" of sorts. Ill give you a scenario: I have the hack with the primary key ID that is equal to 1. In my hacknmod_pictures template it looks like this: files.e-marvels.net/gif/table1.gif pictureHID = The hack that the picture relates to. So if I run my script and I have a html textarea tags in it I will get something like this in my hacknmod_temppictures files.e-marvels.net/gif/table2.gif As you can see it seems to be that the function has executed twice, or something similar. I have check everything I can think of. I have counted the number of times the function goes through a loop and the number of the times the function is executed in a session. If I have the html textarea tags I get the "double" post in the table shown above. The while loop runs two loops and the function exicuted once. If I remove any html textarea tags from the html template I get the results I want. It will not "double" post. Does anyone have any idea why this is happening? PHP FUNCTION: PHP Code:
HTML TEMPLATE: HTML Code:
|
|
|
|
|
|
#2 (permalink) |
|
geek
|
COMMENTS PHP Code:
Why does you regexp pattern match and empty set of square brackets? and the question mark at the end was/is not necessary. the question mark makes the * ungreedy so that the pattern would not match the ending bracket but your patterned can't match and end brackets so it's just wasting space. Code:
Code:
also if you're using regexp you shulding need to do this... PHP Code:
try this pattern and print out the array you'll see the contents of your square brackets are already on their own. Notice the round brackets. Code:
PHP: Pattern Syntax - Manual Maybe if you comment your code we wold be more willing to help... I'm too lazy to run through your code line by line trying to figure out exactly whats happening. |
|
|
|
#3 (permalink) | ||
|
Registered User
Join Date: Feb 2007
Posts: 31
|
Well Ill give you a simpler function that does the exact same thing. PHP Code:
Basicly it doesnt matter what I put in that function, if I send a html textarea tags to the browser its as if the function executes twice. Quote:
Because thats what Im looking for. I look through the code to find a set of square brackets. When I do I take whats inside of it and process that though my script to insert information in place of it. Quote:
|
||
|
|
|
#4 (permalink) | ||
|
geek
|
Quote:
Then it's likely the problem is not in the function itself but in w/e code calls the function. Quote:
|
||
|
|
|
#5 (permalink) |
|
Registered User
Join Date: Feb 2007
Posts: 31
|
Well I removed the textarea from within the function and move it out right before the function is called. Tested it and it still gave me the problem. I then move the textarea to the very first one line of my index page (Out side of any php tags) and I still get the problem. So from what I can see, if there is a textarea on the page it will screw up. So I dont think this is a problem with my coding anymore. Its just a strange set of code that makes no sense to me at all. I cant imagine how it could possible screw something up like that. Im going to some more test to see if any other query's mess up. I have other function on my webpage that run same generic html template The only difference is I insert more information into the edit hack template than something like the add hack template. The addHack function works perfectly except if I have add the html textarea anywhere, such as the very first line. Last edited by SpooF : 05-05-2007 at 13:47. |
|
![]() |