Jump to content

Adam

Moderators
  • Posts

    5,717
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Adam

  1. Here you go: /^[a-zA-Z]+$/ That will require at least 1 character a-z A-Z for a successful match.
  2. This would fall down to the responsibility of the application, not the database.
  3. You could set a PHP session variable to store the time the counter was started, and the time it needs to go off. Then just pass those values 'dynamically' into the JavaScript to configure it correctly..
  4. Fair enough, I hadn't read anything about performance being faster with it. Although using \d you wouldn't actually need the block brackets: preg_match('/^\d{5}$/', $id)
  5. Adding to what Anti-Moronic posted, you also need to handle the errors. Echoing out an error message will simply just print the message and the script will move on to the insert (once it's been moved) - you need to handle the errors. There's about a million ways to handle errors, so here's a very simple example using exceptions (a "try..catch" block): try { if (!preg_match('/^[0-9]{7}$/', $_POST['sid'])) { throw new Exception('Invalid ID format'); } $sql = "SELECT StudentID FROM student WHERE StudentID =" . $_POST['sid']; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_num_rows($query) > 0) { throw new Exception('ID already taken'); } $sql=" INSERT INTO Student (StudentID, StudentName) VALUES ( '" . $_POST['sid'] . "' , '" . mysql_real_escape_string($_POST['sname']) . "' ) "; $insert = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); echo 'Success'; } catch (Exception $e) { echo $e->getMessage(); } Within the try block, if an exception is thrown the catch block will handle it and nothing else within the try block will be executed. This is useful for situations like you have, where you don't want to continue execution of a certain part of the script if there's an error. I've left the MySQL errors using trigger_error() still though, as they're not strictly application errors, but fatal errors that should be fixed during development; on a production website you'd hide PHP errors so the end-user never seems them using: ini_set('display_errors', 0); Hope this helps.
  6. Yeah, this may help: http://www.problogdesign.com/wordpress/use-wordpress-as-a-php-framework-for-your-static-html-pages/ I haven't actually read it but seems to be on about what you're wanting to do.
  7. Hmm well as I said, just requires a basic query: if (!preg_match('/^[0-9]{5}$/', $id)) { // invalid format } $sql = "SELECT id FROM table_name WHERE id =" . $id; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_num_rows($query) > 0) { // already taken } You'll need to handle the errors of course.
  8. You can use regex to validate the format: if (!preg_match('/^[0-9]{5}$/', $id)) { // invalid } Not sure what you mean by 'checking existing ID', but that should just be a simple query.
  9. It's a very professional and high-quality website. Normally I'd suspect a theme or template at this point, but I can tell from your portfolio that's not the case. Well done! I don't think I have any improvements to suggest to be honest.
  10. Do you mean creating the actual image, or the script to display and hide it during the request?
  11. There's no way of doing this with JavaScript. There's the accept attribute for file inputs, however it's not supported by any major browser. The W3C's HTML5 specification of the file input does specify the accept attribute again, so I'm not sure if this will be supported later or not.
  12. Can you describe this a little clearer please? In what way do you mean hide it (CSS wise)?
  13. Did you use !empty() or empty()? Problem being with your code is that the problem could lie in a number of places. Have you debugged each query result to ensure they're what you expect? e.g.. if ($random == 1) { $query = "SELECT * FROM users WHERE clicks > 20 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); // DEBUGGING var_dump($row); // -------- if (isset($row['id'])) { return '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } $random++; } Have you added echo statements within each IF block to flag which are actually being evaluated as true? function scan($random) { if ($random == 1) { echo 'random = 1'; // DEBUG $query = "SELECT * FROM users WHERE clicks > 20 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { return '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } $random++; } if ($random == 2) { echo 'random = 2'; // DEBUG $query = "SELECT * FROM users WHERE clicks > 10 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { return '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } $random++; } if (in_array($random, array(3,4,5)) { echo 'random = 3 or 4 or 5'; // DEBUG $query = "SELECT * FROM users WHERE clicks > 0 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); return '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } } Debugging is really an essential skill you'll need to learn, but try those for now and see if they highlight the problem.
  14. You mentioned the form data is submitted, where to? You may be able to simply improve the efficiency of the code to get around this problem, rather than thinking up hacky solutions. Even just upgrading the PHP/MySQL(?) version on the server, and redoing some of the vital code could help to improve things.
  15. empty
  16. Using base64_decode you can reverse engineer their efforts fairly easily, just may appear more complicated than it is (which was obviously their intention).
  17. They've used a series of messy bas64_encode calls to encode the copyright notice.. to try and stop you removing it (at the cost of performance).
  18. I'm not sure what this function is meant to do, but personally I'd have it return the HTML if it's successful, or increment the value of $random and move to the next IF condition if not: function scan($random) { if ($random == 1) { $query = "SELECT * FROM users WHERE clicks > 20 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { return '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } $random++; } if ($random == 2) { $query = "SELECT * FROM users WHERE clicks > 10 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { return '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } $random++; } if (in_array($random, array(3,4,5)) { $query = "SELECT * FROM users WHERE clicks > 0 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); return '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } } Then to call it: echo scan($random); Also you can't have an expression like: $random == 3 OR 4 OR 5 .. The best alternative here is to use in_array like I have done in the code above. Although I'm sure this function could be improved a lot more if I understood what it was meant to do.
  19. Not sure how you ahcieved this, but here's a way for anyone else it may help.. The JavaScript: <script type="text/javascript"> window.onload = function() { document.getElementById('industry').onchange = function() { redirectToIndustry(this.value) }; } function redirectToIndustry(loc) { window.location = loc + '.php'; } </script> The HTML: <select id="industry" name="industry"> <option value="">Select an industry</option> <option value="digitalmedia">Digital Media</option> <option value="software">Software</option> </select>
  20. You'd use some form of flag (most likely a parameter passed within the URL), to tell the PHP to display the banner originally.. Then yeah you'd need to use JavaScript for the fade effect. This is extremely easy to do with jQuery: <script type="text/javascript" src="/path/to/jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#elementID').delay(5000).fadeOut(); }); </script> http://api.jquery.com/delay/ http://api.jquery.com/fadeOut/ It does mean you'd need to include the jQuery framework, but it's only 26k and saves you the cross-browser headaches. If you'd rather not use jQuery, this tutorial may help: http://www.switchonthecode.com/tutorials/javascript-tutorial-simple-fade-animation
  21. order by price desc?
  22. That's just the number in 'scientific notation'. You can format it to a more readable value using number_format or sprintf (..with the 'e' type specifier).
  23. You always have to use mysql_query() to send a query, when using the MySQL extension of course.
  24. You're not actually making a query; you first need to pass the SQL code to mysql_query, and then pass the returned resource to mysql_fetch_assoc.
  25. Page 1 should read from 4.txt? That makes no sense. Not to mention over complicating this by reading eight 'entries' from one file, and seven from the other. Why not just use a database for this? You'll save yourself a lot of headaches. Here's an example of how you could set this up: Table structure: id | name ---------- 1 | john 2 | bruce 3 | etc Your descrpition of the 'entries' is a little vague so that's best I can suggest there. The queries you'd need to select them: -- page 1 select name from table_name limit 0, 15; -- page 2 select name from table_name limit 15, 15; -- etc. And roughly the PHP you'd need to generate those queries and output the entries: // check if the page number was passed $page = !empty($_GET['page']) ? intval($_GET['page']) : 1; // calculate the limit values $length = 15; $start = ($page - 1) * $length; // build the sql $sql = "select name from table_name limit $length, $start"; // query the database $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); // make sure rows were returned if (mysql_num_rows($query) > 0) { // loop through each row while ($row = mysql_fetch_assoc($query)) { echo $row['name'] . '<br />'; } }
×
×
  • 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.