-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
Well it sounds like you're going to have to do some mapping of answer combinations to array entries, regardless. I don't think there's really any way around that, though you could automate the mapping.. for example, you can generate the possible combinations to answers easy enough with a script, though I suppose the list and time it takes would grow exponentially based on how many questions and answers there are.. but in any case, you could then hash each combination (again, you can automate this..just throw this into the script that generates the answer combinations) and then use the hashes as the array keys to your array.
-
this preg_replace isn't doing that.. the URLs already have your site address in them by the time $string is passed to it. Or else, the URLs are relative links and you are looking at the rendered html on your page..well since they are relative urls, the browser points to your site. In any case, this preg_replace isn't the issue.
-
Adding isset() causes database value to be ignored
.josh replied to ICYUH8's topic in PHP Coding Help
For example, here is another part of your code that tries to use array indexes in a condition without first seeing if they are set: else if(strlen($_POST['hou_title']) < 5) $error = "Title too short. 5 character minimum required"; else if(strlen($_POST['hou_desc']) < 5) $error = "Description too short. 5 character minimum required"; else if(intval($_POST['hou_areax']) < 1) $error = "Invalid house area measure X"; else if(intval($_POST['hou_areay']) < 1) $error = "Invalid house area measure Y"; else if(intval($_POST['hou_rooms']) < 1) $error = "Invalid rooms specification"; You need to throw an isset into the mix on all of those. Basically anywhere in your code where you use a variable or array[index] in a condition you need to first check if it is set. Look at the error messages, they tell you what vars/indexes are the offense. Then ctrl+f for them. -
Adding isset() causes database value to be ignored
.josh replied to ICYUH8's topic in PHP Coding Help
As I said before, the isset needs to come first. There is no difference between that 2nd one and putting it in separate if statements, so you shouldn't need to do that. Did you apply this to ALL of your conditions? Look back at your warning messages: you are getting multiple warnings, each for different indexes. IOW you need to apply this to more than one place in your code. -
why would you want to get "expected results" out of something that is supposed to return a randomly selected entry? If you want to be able to pass an argument and receive a specific result, it's no longer random thing. Perhaps you aren't explaining it right, or perhaps I am not understanding it right? In any case, since you are trying to control or otherwise influence the random selection, instead of using the built in functions that shuffle or return a random entry, you'd use the functions that return a specifically specified entry, and then just write your own "randomize" logic, around whatever you pass to the function. So IOW you'd be using things like count or array_keys to get info about the array.
-
Adding isset() causes database value to be ignored
.josh replied to ICYUH8's topic in PHP Coding Help
To clarify, isset returns a boolean value of true or false, so basically your condition is saying: if the array index is set: if (true=="Y") or if the array index is not set: if (false=="Y") Yes, try changing your condition to what Muddy_Funster showed - however, you need to reverse it. This will still give you the error, since you are evaluating the value first. if($settings['set_payment']=='Y' && isset($settings['set_payment'])) { This will first check if the index is set, and will prevent the error, since the 2nd half of the condition won't be evaluated if the first half is false. if(isset($settings['set_payment']) && $settings['set_payment']=='Y') { -
preg_match \ preg_replace functions for embedding youtube\soundcloud\etc.
.josh replied to doofy's topic in Regex Help
preg_match only matches for and returns the first thing found. preg_match_all will look for all things that match the pattern. Basically the issue is that you are finding and capturing the first id.. and then using preg_replace to replace all of the ids with that first id. The best way to fix this is to skip trying tp preg_match or preg_match_all and incorporate what you have there into preg_replace. -
yeah..not gonna bother sorting through a shitton of code, but it sounds like you have a really old script and your host got around to upgrading to a more recent version of php. As for the specific error mentioned in your thread title: http://forums.phpfreaks.com/topic/268091-ereg-and-deprecated-error/ Overall my suggestion to you would be to take the time to rewrite your script with updated code, or find someone to do it for you (which will most certainly involve money).
- 1 reply
-
- ereg_replace()
- pereg_replace()
-
(and 3 more)
Tagged with:
-
gratz and other fancy stuff. .josh
-
$pattern = '#(?:\?|&)linkauth=([^&\'"]+)#'; make sure it's linkauth and not someothervarendswithlinkauth. Also cover for if it's the last url param.
-
but...that's exactly what you said you wanted, yes? If you want it to match starting at beginning of string, instead of anywhere within string, then remove the first %
-
SELECT * FROM certificado WHERE nome LIKE '%{$name}%'
-
you are missing a comma after this one: "/magician-winchester.html" => "magician-winchester"
-
okay, are you sure $username has the expected value? If you run the query directly in mysql (via phpmyadmin or commandline) do you get expected results?
-
dumb question.. are you sure you are properly connected to the db and all that? do this: $maxscore = mysql_query("select (max(scoreioa) + max(scoreioa2)) from result where username='username'") or die(mysql_error()); $row = mysql_fetch_row($maxscore); echo "<pre>";print_r($row); echo "</pre>"; $scoremax = $row[0]; echo $scoremax; do you get any errors displayed? what does the print_r show? what is echo'd out? is 'username' really the username?
-
Fetching last characters after "=" sign
.josh replied to WebDesignerDeveloper's topic in PHP Coding Help
$url = "http://www.abc.com/index.php?site=new"; $parts = parse_url($url); parse_str($parts['query'],$query); echo $query['site']; // this will have your value -
I seriously cannot figure out what's wrong with this! (EDITED files)
.josh replied to Craptacular's topic in PHP Coding Help
hi. please do not make multiple threads asking the same thing. -
I seriously cannot figure out what's wrong with this!
.josh replied to Craptacular's topic in PHP Coding Help
yeah.. sorry that you've been pullin' your hair out for 2 days now, but not gonna sort through tons of code. But in general, here are some tips to help: 1) You said it works for some of your items, but not all. This usually means that you've typoed a variable or form field name somewhere. Make sure the form field names line up with your $_POST variable and whatever other variable(s) you push it to. Also make sure they are not typoed in your query string, columns in your table are right, etc.. 2) make sure your form is actually pointing to your single.php. I know this is probably dumb but you never know. Maybe you have several scripts and forms floating around and you're pointing to the wrong one 3) Add the following to your single.php echo "<pre>";print_r($_POST);echo "</pre>"; exit(); This will dump what was received from your form. Make sure the expected variables/values are there 4) echo out your db query string (whatever variable you put your query into): echo $query; exit(); Make sure it looks right. Copy and paste it directly into your database via phpmyadmin or commandline or however else you directly interact with your database. Does it throw an error? 5) add the following to your query execution (not sure what you are using, but hopefully you can figure out the equivalent for you) : $result = mysqli_query($conn, $query) or die (mysqi_error()); Does this produce an error? -
One way to do it is to have a database table with 2 columns: an ID column and a timestamp column. Each time the form is submitted, insert a row into the table with the current timestamp and ID of the user. If you require the user to be logged in, you can use their ID associated with their login that you should already have. Also, requiring login will make it easier to enforce your limit. If you do not require login, you can use their IP address instead. This can easily be spoofed (e.g. user goes through a proxy service) but there's no much you can do about that, except to make them login. Then you will have logic that selects by the ID for the last hour and if there's more than 10 entries, give an appropriate message instead of performing the lookup. Should prolly make an additional script to purge old data and put that on a cron job, unless you want to keep records for something else (e.g. showing user a history of use, etc.)
-
trim will trim from beginning and end. ltrim will trim only from the beginning.
-
I don't think it's too much to expect regular members to use code tags. And I'm sure you did just forget. Which is why it was a 1 point warning that expired almost immediately. I mean really, it was the equivalent to a PM. Also, this happened like 7 months ago. You're just now getting around to seeing it and saying something about it? Which means you haven't been active for like 7 months. I think someone woke up on the wrong side of the bed today.
-
sorry, i wasn't trying to be grumpy or nitpick.. i only wanted to point it out because they are two different things, and if you happen to go searching for answers elsewhere, using "java" as a keyword instead of "javascript" will give you vastly different results.
-
first off, this is javascript, not java. Two completely different things. 2nd, your code only does that because that's all the code actually does. Where is the code that actually retrieves the shoutbox content?