Jump to content

Wolphie

Members
  • Posts

    682
  • Joined

  • Last visited

    Never

Everything posted by Wolphie

  1. Couldn't PHP automate the process a bit though? For example, if you had a compiler locally, you could use PHP to initiate the compiler and send the executable to the browser for download? Could be wrong, though.
  2. Sorry, I didn't read correctly. This should be what you're looking for, however your array has duplicate array keys, so it will only return the first occurrence. <?php $fruit = array("Apple" => "Apple", "Orange" => "Orange", "Banana" => "Banana", "Kiwi" => "Kiwi", "Mango" => "Mango"); $rand_key = array_rand($fruit, 3); if (is_array($rand_key)) { foreach ($rand_key as $key) { echo $key .' - '. $fruit[$key] . '<br />'; } } else { echo $rand_key .' - '. $fruit[$rand_key]; } ?>
  3. <?php $fruit = array("Apple", "Orange", "Banana", "Kiwi", "Mango"); $rand_key = array_rand($fruit, 1); echo $fruit[$rand_key]; ?>
  4. His use of it doesn't provide a lot of security no, and that function isn't really designed for security. It's designed and it is there for validation purposes and when used correctly, it's very useful, and powerful.
  5. Well, hopefully in your database table you store the ID of the person sending the message, and the recipients ID. Just click on their message, get the ID of the recipient from the database and use that as the recipient once again. If you reference the ID of the message you're replying to in the URL, for example reply.php?id=67 You can then continue to pull all of the information from the database for that message ID, and retrieve the subject, the message, the recipient, the sender, etc..
  6. http://php.net/manual/en/function.filter-var.php does a lot, actually.
  7. No semi-colon at the end of mysql_close($con)
  8. Wolphie

    CSS Help...

    This should be in the CSS forum, not the PHP forum.
  9. You can't really make it work like that, you would have to convert the data in the database to a time integer and then compare it with time() http://php.net/manual/en/function.time.php
  10. That's because $items['subcategory'] doesn't exist. $items is already an array, and you're making another array inside each element of the $items array to store your data. e.g. $items[0]['subcategory'] would return the data for the first row in the database. $items[1]['subcategory'] would return the second and so on.
  11. Okay, so I have this <a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a> which matches all links and returns what I need it to. But how would I go about making it so it only returns the links of a specific class?
  12. This should work <?php function archive($files = array(), $destination = '', $overwrite = FALSE) { if (file_exists($destination) && !$overwrite) { return false; } $valid_files = array(); if (is_array($files)) { foreach ($files as $file) { if (file_exists($file)) { $valid_files[] = $file; } } } if (count($valid_files)) { $zip = new ZipArchive(); if ($overwrite) { $zipcreate = $zip->open($destination, ZIPARCHIVE::OVERWRITE); } else { $zipcreate = $zip->open($destination, ZIPARCHIVE::CREATE); } if ($zipcreate !== TRUE) { return FALSE; } $zip->close(); return file_exists($destination); } else { return FALSE; } } // Example $files_to_zip = array('images/1.png', 'images/2.png', 'read.jpg'); $result = archive($files_to_zip, 'my_archive.zip'); ?>
  13. You're using the same namespace for the function. The class is already named DBCon, and inside that class you also have a function named DBCon. <?php class MySQLConn { function __construct($username, $password, $database, $host = 'localhost') { $conn = mysql_connect($host, $username, $password); if ($conn) { if (mysql_select_db($database, $conn)) { echo "Success"; } else { echo "Failed"; } } } } // This will automatically connect to MySQL once the object has been initiated because of using a constructor $db = new MySQLConn('username', 'password', 'database_name'); ?> http://www.php.net/manual/en/language.oop5.decon.php
  14. To begin with, the problem you're having is on line 4, which is when you're defining a class. A class isn't a function, when you define a class you don't need parentheses (the brackets). When you initiate a class, you should include them though. You should also have some kind of error handling, using or die() is bad practice, especially so in OOP.
  15. You should be using "\n" to generate a new line. echo "<!-- BE SURE TO SELECT TAGS: \n"; if(isset($_POST['Tag_Tesla'])) { $Tag_Tesla = $_POST['Tag_Tesla']; } else { $Tag_Tesla = array(); } $i = 0; //first index while ($i < count($Tag_Tesla)) { echo "Magnet Strength = $Tag_Tesla[$i]\n"; ++$i; } if(isset($_POST['Tag_Op_System'])) { $Tag_Op_System = $_POST['Tag_Op_System']; } else { $Tag_Op_System = array(); } $i = 0; //first index while ($i < count($Tag_Op_System)) { echo "Operating System = $Tag_Op_System[$i]\n"; ++$i; } if(isset($_POST['Tag_Age_Class'])) { $Tag_Age_Class = $_POST['Tag_Age_Class']; } else { $Tag_Age_Class = array(); } $i = 0; //first index while ($i < count($Tag_Age_Class)) { echo "Age class = $Tag_Age_Class[$i]\n"; ++$i; } echo "-->\n"; echo "<br>\n"; echo "<!-- BE SURE TO SELECT CATEGORIES: \n"; if(isset($_POST['Category_MSK'])) { $Category_MSK = $_POST['Category_MSK']; } else { $Category_MSK = array(); } $i = 0; //first index while ($i < count($Category_MSK)) { echo "MSK = $Category_MSK[$i]\n"; ++$i; } echo "-->\n";
  16. If the files are local, then you shouldn't need to do any file transfers, but rather just provide the path name to the directory. This is just an example, appropriate error handling is required. <?php // Open directory $dir = opendir('path/to/directory'); // List files in images directory while (($filename = readdir($dir)) !== false) { if ($filename != '.' || $filename != '..') { // You will need appropriate error handling $sql = mysql_query("INSERT INTO table_name ( filename ) VALUES ( '". $filename ."' )"); } } closedir($dir); ?>
  17. You'll need to use JavaScript.
  18. This is reasonably easy to do if you've already created a registration/login system before. Although I don't understand why you'd store usernames as an MD5 hash in the database? Unless you mean passwords? When they go to reset the password simply ask them to verify their current password, enter a new password and verify the new password. Once the user hits submit, check to see if their old password is correct, if so, proceed to encrypt the new password and then replace the old one in the database with the new one.
  19. $AuctionRate is a string, so you need to surround it in quotes. $result = "UPDATE auctiontransfer SET AuctionRate = '". $AuctionRate ."' WHERE ID = ". $ID;
  20. I'm pretty sure you can achieve the layered effect using CSS.
  21. I think you would have to have it so when a user clicks the print icon below the image, a pop-up window would be displayed which shows only that image, with another print icon which actually triggers the print command. I'm not sure if it's possible to just print a certain part of the page.
  22. You can't get the row ID using PHP unless it's in the URL. You'd have to use JavaScript to get the row ID and then process it using AJAX.
  23. On the form element you use <form action="thepageyouwishtogoto.php" method="POST"> <textarea name="message"></textarea> <input type="submit" name="submit" value="Send" /> </form>
  24. Yes, since with my code you're checking to see if magic_quotes_gpc() is enabled, and if so remove the slashes. I'm also using mysql_real_escape_string() to escape any possible malicious code.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.