![]() |
Small php error - Thank you in advance!
there is no error outputted but i know the problem is in the preg_match part. Some assistance would be great!
Thank you! Rules for preg:match, and to blur for me to read ;) PHP Code:
PHP Code:
|
PHP Code:
PHP Code:
|
still the same..
|
CODE EDIT:
PHP Code:
|
I tried your code and the preg_match is always returning a value, but I am guessing you just want to catch url's that come from youtube? it's a regex problem, I am not an expert in that area, but it would help to know what are you trying to match in the url.
|
Your call to
preg_match isn't going to work, you need to follow preg_match(pattern, test_string) for what you're trying to do with it. Also, in the if statement below it, you're assigning TRUE to the $check variable; not comparing its value to TRUE, use the double equals operator ($check == TRUE) (or ($check === 1), or simply ($check)). |
If you don't mind me asking, what do you mean by test_string ?..
PS: Thank you for the help everyone! |
The string you want to search in with the expression.
|
Now when i try to submit anything i get blankpage :S?
|
because your preg_match is returning 0 or false I guess, either that or the script is failing further up, put an else on the preg_match if statement and see if it shows, this will tell you that there might be a problem with the regex (if the string passed is known to be a valid string)
Also its pointless assigning the result of preg_match to a variable in this case as it will only result in the number of times the pattern matched and because it stops at the first match, this will be either 0 or 1 (or false if it failed in some way). As PHP uses 0 and 1 as true and false the result will only ever be true or false. This would be a better way of doing it: PHP Code:
|
@sketchMedia it works now, no blank page anymore but..
it wont block out none youtube links i can write bla bla and it will accept it.. any ideas? Thank you.. |
You don't have an else for if the link is invalid. That would be the reason for your blank page. Try this code:
PHP Code:
|
Thank you, Wildhoney! you're the best!
PS: anyone know how i can block out so that you can not post the same link twice, maybe just do a check from db and see if that exists then print out this already in db ? any ideas! thank you! |
Use 'IGNORE' on the INSERT statement.
sql Code:
|
sketchMedia, it did not work.
|
Quote:
link column has a unique index on it. The important thing is the index, it's up to the dev if they want to use ignore or go with the error generated when an insert tries to duplicate a unique key. |
so if i change it to a unique.. it would work?
would it also make other problems? |
PHP Code:
THANK YOU TANAX!^^ |
Whilst that does work, just bear in mind that Salathe's approach is the more professional approach. You would make the link column an index, and set the unique property on it, you would then handle the response from MySQL.
|
could anyone give an example on how to do that?
and thank you for taking time to help out i am grateful! |
| All times are GMT. The time now is 08:47 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0