scootstah
Staff Alumni-
Posts
3,858 -
Joined
-
Last visited
-
Days Won
29
Everything posted by scootstah
-
Help me understand this really basic function please
scootstah replied to mr cracker's topic in PHP Coding Help
Huh? The purpose of the return is to supply mysql_query() with an active connection, nothing more. -
Help me understand this really basic function please
scootstah replied to mr cracker's topic in PHP Coding Help
In your example $con would never exist, even if the function was run. -
Php includes - re-directing to blog.mycomapny.co.uk HELP
scootstah replied to adipalmer123's topic in PHP Coding Help
Ah, now I see. The coffee helped. I assume you would want to redirect traffic to the relevant blog article, rather than just the main site? Like, blog.maplewebdesign.co.uk/some-article redirects to maplewebdesign.co.uk/index.php?page=blog&article=some-article, or something. If yes your best bet is probably some .htaccess rewrites. -
Php includes - re-directing to blog.mycomapny.co.uk HELP
scootstah replied to adipalmer123's topic in PHP Coding Help
Not really. Post code please. -
Help me understand this really basic function please
scootstah replied to mr cracker's topic in PHP Coding Help
It would, but since there is no active connection at the time mysql_query is called, you have to pass it the connection that was created by Connect::con(). If you call Connect::con() before mysql_query, you don't have to return anything. -
EDIT: Whoops, thought that was the edit button. :/
-
1. You're going to need to give more code. With the code you have, there's no explanation why it would work in one file and not the other. The issue lies in other code on the page. 2. You may try the Sender header or the envelope-sender command line parameter.
-
Not sure it will work in all situations, but a simple str_replace should do the trick. $url = "http://www.youtube.com/watch?feature=player_embedded&v=IwPHy17Iu6E"; $url = str_replace('feature=player_embedded&', '', $url);
-
Putting mysql_error() in your die() will show any query errors, helping to pinpoint the error (if any) in the query. Also, you really shouldn't use or die() on queries in a production environment. Ideally, you shouldn't use it at all, but especially not in production. All it's going to do is help hackers break your app, and not alert you of a problem in the slightest. So unless someone reports it, you'll never know if a query breaks.
-
You should polish that up a little and throw it in the snippet repo, it looks pretty useful.
-
Help me understand this really basic function please
scootstah replied to mr cracker's topic in PHP Coding Help
That's actually not a very good way to do it. You are potentially creating a new connection with every query, which is needless overhead. To answer your question, though, the second parameter of the mysql_query function is the link identifier. Basically, it is which active MySQL connection to use. If you only have one active connection it will automatically use that. The reason you must return $con is because you presumably don't have an active connection until Connect::con() is run. Based on that logic, then, this should also work: Connect::con(); mysql_query($somequery); -
You can't use variables in single quotes without concatenating. So do either this: $datealt=strtotime("$date ,$hours:$minutes:00"); or this: $datealt=strtotime($date . ' ,' . $hours . ':' . $minutes . ':00');
-
Yep. And it was incoherent, to be honest. What it had to do with my Original Post is beyond me. You provide code when you ask a coding question, why would you not provide database information when you ask a database question? And yes, this is a database question. Database queries may be implemented in code but are independent from it. Having no samples to actually test, I have come up with this. I don't know if it's what you want or not: // Build query. $q2 = 'SELECT m.first_name, m.username, m.photo_name, m.photo_label, m.location, m.created_on, m.logged_in, m.last_activity, c.created_on, c.body, c.status, (SELECT COUNT(*) FROM comment WHERE member_id = m.id) AS post_count FROM member AS m INNER JOIN comment AS c ON m.id = c.member_id WHERE c.status="Approved" AND c.article_id=? ORDER BY c.created_on';
-
It's not $_SERVER that is unsafe, it is certain indexes of $_SERVER, such as PHP_SELF which can be manipulated by the client to pose a potential XSS attack.
-
Are you using CodeIgniter? The segment method returns false by default if there is no segment. So all you'd need to do to check if a segment exists is: if ($this->uri->segment(3))
-
Tip: use an editor with bracket highlighting and you'll be able to easily see. However, you have too many parenthesis. You can rewrite this as such: if(isset($this->uri->segment(3)) && (empty($this->uri->segment(3)) || $this->uri->segment(3) === false || trim($this->uri->segment(3)) == ''))
-
Sometimes you may want to have things change in your overall layout depending on what page you are on. For example using menus which expand; you may want to expand the current page item.
-
PHP_SELF opens up XSS attacks. It should be avoided, especially when there are better ways to work. Such as SCRIPT_FILENAME or SCRIPT_NAME.
-
Or Dependency Injection. Singletons are as bad as globals if you abuse them.
-
$_SERVER['PHP_SELF'] is not safe, so don't use it.
-
It means you will be connecting to the database more than once, which doesn't make any sense. You are just wasting server resources. Connect to the database before anything else, and then you don't have to worry about it.
-
Why would you want to do that?
-
Define automatically. Click one button and it's done? Make it run by itself every day?
-
When you require_once something, it does exactly that: requires it once. Any subsequent attempts to include the file fail, because you said you only want to do that once. So you are essentially doing: require_once(WEB_ROOT . 'private/mysqli_connect.php'); ... more code ... require_once(WEB_ROOT . 'private/mysqli_connect.php'); Therefore, the second one won't work. The easiest thing to do here is to just connect to the database earlier than last_activity and don't worry about closing it.
-
If you use something like phpMyAdmin, you can export the data from the members table and then insert it back into the users table.