scootstah
Staff Alumni-
Posts
3,858 -
Joined
-
Last visited
-
Days Won
29
Everything posted by scootstah
-
The issue from my last screenshot is fixed. However, the nav menu still has a scrollbar when you expand the menus. This looks like a design decision and not a bug, but personally I would still prefer that it expanded the whole page and used a normal page scroll. However, that's just my opinion and preferance. It looks like the bug has been fixed.
-
Either you made it worse, or it renders a lot worse on Linux. http://i.imgur.com/osHCL.jpg EDIT: I was on Windows 7 in my other post.
-
It's because the query failed. Use mysql_error to find out why. Your class is a bit over zealous though. A class called "DB_Functions", to me, sounds like a class for utility database functions. But instead, you have a bunch of user related methods. Would this not be better suited in its own User class? function __construct() { require_once 'DB_Connect.php'; // connecting to database $this->db = new DB_Connect(); $this->db->connect(); } I have a few issues with this. require_once 'DB_Connect.php'; This makes your class very inflexible, because now it relies on specific file structure and files being available. What would be better, is if you passed in your class to the constructer. function __construct(DB_Connect $database) { $this->db = $database; $this->db->connect(); } My other issue is that, it seems like you are trying to use the mysql_* library in a half-assed OOP fashion, no offense. It was never intended for that, and it doesn't support that very well. Why not instead use the mysqli_* library or PDO library, which support OOP fully?
-
mysqli fetch_all() and fetch_array() errors
scootstah replied to nodirtyrockstar's topic in PHP Coding Help
Try this: $bandArr = $result->fetch_array(MYSQLI_NUM); echo '<pre>' . print_r($bandArr,true) . '</pre>'; What do you get? EDIT: Actually, the undefined offset error is because your query is only returning a single column.- 4 replies
-
- mysqli
- fetch_all()
-
(and 1 more)
Tagged with:
-
Considering he posted in "PHP Help", it sounds like a web issue.
-
Probably the biggest change/most beneficial change would be to make it OOP. This will allow you to re-use code, and maintenance will be easier. For example, I see this block of code being used multiple times: //### Make sure the defenders health does no go below 0 if($attackHit == 1) { if(($defender['health']-$attackPower) < 0) { $defender['health'] = 0; } else { $defender['health'] -= $attackPower; } } Wouldn't it be better if, when you need to damage someone, you didn't have to repeat this logic? You could simply call a class method like, $defender->decreaseHealth($attackPower); If you come up with another way that someone might take damage (like some form of self damage, maybe from falling or from a confusion spell), you only have to call this method. On that note, your logic for this particular case can be simplified to: if ($attackHit == 1) { $defender['heath'] = max(($defender['heath'] - $attackPower), 0); } The max function, in this case, will not let the number go below 0. It will return the higher value of the arguments given, and since 0 is > -N, it will return 0. I didn't thoroughly go over your code, this just stuck out at me as I was looking for an OOP example. Also, try to use proper data types in your code. Instead of having $attackHit equal to 1 or 0, make it an actual boolean (true/false). It makes more sense to people reading your code.
-
When the users upload a file, store it and its size into the database. Then when they next try, add up all of the sizes to determine if they can upload another. Obviously this only works via a web-form. If he is using FTP or some other means, he will have to do something different. .quota files is a possibility.
-
I'm using 1920x1080 on a 24". It gives me vertical scrolls as well. http://i.imgur.com/dHFzw.png
-
How are you storing items in the cart? Does that go to a database table, to a session, to a cookie, etc? In any case, I would say you should first select that data separately. Then, run your query to select all products. Then when you loop through all products, see if the ID is amongst that of the "added" IDs.
-
The error is telling you that $target_file is not an Image resource. This means that, further up the code, that Image resource did not get created properly. Most likely because the image failed to upload. The library looks like the standard PHP GD library.
-
The only purpose of a salt is so that an attacker must crack each and every hash to obtain the password. That's it. It doesn't have to be super secret, and it doesn't matter if the attacker knows what it is. They still have to generate the hashes individually, so it has served its purpose. Running hash functions on random bits of data is doing absolutely nothing in regards to security. If you have a good hashing algorithm, it doesn't matter if the attacker knows how it was computed. They still have to brute force each hash individually. If you use something secure like bcrypt, this will take an unfeasible amount of time (read: years) and so it's just not going to happen. So to summarize: using a good hashing algorithm means that even if your database is compromised, and even if an attacker knows what the salt is, and even if the attacker knows how to construct the hash - you're still safe.
-
Breadcrumbs displayed using table info from MySQL
scootstah replied to dmfgkdg's topic in PHP Coding Help
join() is an alias of implode().- 11 replies
-
- php
- breadcrumbs
-
(and 2 more)
Tagged with:
-
Eh, no, not really. If using it once isn't secure, then using it twice isn't secure either. Use something like PHPass. Cryptography is hard, you can't just pull some random crap out of your ass and expect it to be secure.
-
Eh, you're going to have to be a little more descriptive than that. "Doesn't work" isn't going to cut it, there are 100 results that might classify as "doesn't work".
-
I don't know how I can show you with any more clarity unless I come type it on your keyboard. Look in your original code for this snippet: $insertSQL = sprintf("INSERT INTO test (title, detail) VALUES (%s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['detail'], "text")); Delete it. Now, where that code used to be, add: $detail = str_replace('<br xmlns="http://www.w3.org/1999/xhtml" />', '<br />', $_POST['detail']); $insertSQL = sprintf("INSERT INTO test (title, detail) VALUES (%s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($detail, "text"));
-
I did. But instead you copy/pasted it to a random section of your code.
-
Well, how does StumbleUpon handle those types of things? How do other competitors handle it? Do some research on your competitors and come up with ways to be different, or better in some way. Obviously you will need a lot of users, so now you'll need to figure out how to make people come to and use your site.
-
Without really knowing what you're doing, since you haven't really given any such information, a for loop perhaps? for($i = 1; $i <= 5; $i++) { echo '<input type="hidden" name="item_name' . $i . '" />'; }
-
Of course it didn't work, it's not magic. You have to actually pass in the value of the text field. It looks like if you change: $insertSQL = sprintf("INSERT INTO test (title, detail) VALUES (%s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($_POST['detail'], "text")); To: $detail = str_replace('<br xmlns="http://www.w3.org/1999/xhtml" />', '<br />', $_POST['detail']); $insertSQL = sprintf("INSERT INTO test (title, detail) VALUES (%s, %s)", GetSQLValueString($_POST['title'], "text"), GetSQLValueString($detail, "text")); You should be good to go. However, there are a lot of issues with your code. Blindly passing around $_SERVER['PHP_SELF'] and $_SERVER['QUERY_STRING'] is a huge XSS vulnerability. Don't do that. You should be using hard-coded values that can't be altered by the user. Your "GetSQLValueString" function is pretty useless. Get rid of that and simply use mysql_real_escape_string on input. There's no need to do all that stuff, MySQL will automatically typecast as it needs to. Also, if (PHP_VERSION < 6) { lolwut?
-
Why does a file work in one folder but not another
scootstah replied to mdmartiny's topic in PHP Coding Help
When you call this in your code: ftp_chdir($conn_id, "/path/to/directory"); What is the exact value for "/path/to/directory"? Also, could you place a file in your public_html with this code, and post the result? <?php echo __DIR__; -
$text = str_replace('<br xmlns="http://www.w3.org/1999/xhtml" />', '<br />', $text);
-
The error is because you didn't end the array statement before that line. This could be avoided in the future by 1. using a decent editor which highlights syntax errors, and 2. structuring your code to be more easily read. Compare $mobile_urls = array($domain_www.'/' => $domain_mobi.'/', // Homepage $domain_www.'/page.php' => $domain_mobi.'/page.php', To $mobile_urls = array( $domain_www.'/' => $domain_mobi.'/', $domain_www.'/page.php' => $domain_mobi.'/page.php' );
-
Well I hate to burst your bubble, but that's not how it works. If you want code written for you, head on over to the Freelancing section and pay someone to write it.
-
I copied your code and it works fine for me. If you are using Windows, your issue is probably that Windows uses "\r\n" line endings while Unix uses "\n". I am using Linux, so "\n" works for me. However, you should be populating the array with each line instead of exploding a string. <?php $file = fopen("postcodes.txt", "r"); $members = array(); while (!feof($file)) { $members[] = fgets($file); } fclose($file); if (in_array("SE5", $members)) { echo "Got you"; }
-
A blurb from Phil Sturgeon's blog: So, I suspect the re-write is going to take a little bit of time.