AyKay47
Members-
Posts
3,281 -
Joined
-
Last visited
-
Days Won
1
Everything posted by AyKay47
-
IMO, regular expressions should only be used when searching for a complex pattern within a string as they use more resources. For logic that requires searching for a simple static string within a string, use a string function such as strpos.
-
I don't see anything wrong with the AJAX POST request besides the fact that you are not checking for several key triggers, but this will not affect the actual call. You should be encoding any data that is to be passed through a url/uri via encodeURIComponent() Since you are using a relative path to the landing page, make sure that it is in fact in the same directory as the calling page. What errors if any are being displayed in chromes developer tools?
-
My first thoughts are to build a function that validates Australian addresses and pass any necessary data to that function. Perhaps if you show us the relevant code along with your attempt at it, we can help you further.
-
What exactly do you mean by "it doesn't work", what is happening? Have you tried simply outputting $_POST['q'] and $_POST['r'] to see if the values are correct? Also as a side note, I would recommend using the JavaScript framework JQuery especially when wanting to use AJAX, but also in general; turns 10 lines of code or so into 1 line. Make sure not to use arbitrary user data directly in an SQL statement. Make sure to pass the user input through mysql_real_escape_string to make it safe to pass into the SQL statement. Edit: Also, if you decide not to use JQuery, you will need a try block to determine which http request object the browser uses; IE until version 7 used an Active X Object.
-
Hopefully you are not inserting html into the database, as this would be bad practice and a waste of storage space. mysql_real_escape_string will make any data passed to it safe to use in an SQL statement by prepending any potentially harmful characters with a backslash.
-
The first call to mysql_fetch_array is moving the pointer to the next row. Remove that line and the while loop should work as you expect.
-
Edit: Nope you're right. Memcached is the newer client and should be used.
-
Thank you for that rudimentary lesson Barand. This topic isn't worth any more then one more post as it is menial. What I was trying to point out is that this: if((something == something || something == something) && something == something) is the exact same as: if(((something == something) || (something == something)) && (something == something))) only is much more confusing to look at. parens around a single condition: (something == something) is not needed. To use your example Barand: (A AND B) OR C same as: ((A) AND (B)) OR (C) Edit: What's with the double spacing?
-
Look into using memcache
-
No there is nothing wrong with it, but wrapping each condition in parens AND writing them each on a new line is overkill. The interpreter is not a person, it does not misunderstand. If that is your style then more power to you but I believe that causes more typing then what is needed. The only instance where you need parens in a condition is when you need to specify the order of precedence. Off topic I know, but you called me out.
-
How would you like us to help you?
- 2 replies
-
- login error
- login script
-
(and 2 more)
Tagged with:
-
Question 1: First step would be to check out their RSS feed. Second would be to look into their API available. Question 2: Google's CS API
-
You don't need to wrap each condition in parens. Unless I am missing something, I don't see anything obvious that stands out in the if condition. What debugging steps have you taken so far? Be sure to validate each conditions' value.
-
Example#1 in the PHP manual PDOStatement::bindColumn replicates your logic using PDO::FETCH_BOUND mode.
-
How Should I Properly Structure My Website?
AyKay47 replied to BorysSokolov's topic in PHP Coding Help
Option 1 is the more popular solution as it involves much less coding, allows more control over the overall structure of the website, allows for easier debugging etc... A popular approach to messy URLs is to clean them up using "mod_rewrite" which is something you might want to look into. Now, we cannot give you an end all answer because it depends on what exactly the websites content is, what logic is implemented both front and back end etc. -
Why this reg exp for mobile number does not work?
AyKay47 replied to mostafatalebi's topic in Regex Help
A simple regex should be fine: <?php $pattern = "~^09\d{9}$~"; ?> While you can't guarantee that all numbers that run through this regex will be mobile numbers and not land lines, you can ensure that they conform to the pattern that you specify. -
STOP A couple things on the loadfile() function: 1. Using the global keyword is very bad practice as it causes scope pollution and defeats the purpose of using a function to begin with (bad times). You should be passing any information needed by the function via the functions parameter list. 2. Instead of initializing 5 arrays and storing values in each, you should be building a muti-dimensional array instead. This will make it cleaner and much easier to sort further down in the code. 3. split() is deprecated and should no longer be used, use preg_split instead. I'm sure there are more errors further down but lets start there for now. Also, it would be helpful if you posted any errors that are being displayed.
-
Depending on how complex the subject string can get, I might look into using a PCRE for this. Could save you a lot of coding.
-
Looks good, except the bind_param() call should be outside of the foreach loop.
-
Something important to note, only use fetch_all() in this particular case (e.g. when you only need to store the values into an array). In most other cases, fetch_all() is a complete waste of resources.
-
Fill in the missing pieces of your logic before an appropriate answer can be formulated. An example array would help. Storing multiple values in one array element is not how arrays are meant to be implemented. Something like: $arr = array(); $arr[] = array($id, $aid, $at_points); would be a better solution.
-
If only you would have read it when I posted it.
-
I suggest studying OOP for quite some time before attempting to implement it into your code. You can find quite a few online and book resources on the subject. In short, the above code is not OOP whatsoever. Throwing some code into classes is not what OOP is about.
-
Sigh, $_GET['id'] on the receiving page will hold the value you are looking for. Just make sure to cast it to an int data type before using it in the SQL statement.