Jump to content

DWilliams

Members
  • Posts

    144
  • Joined

  • Last visited

    Never

Everything posted by DWilliams

  1. In any sane database setup you a. shouldn't be allowed to have a NULL id (assuming ID is your PK, that's the name most people use for every table's PK) and b. shouldn't need to specify an ID with auto increment on So check your database design and see if it even allows a null value in the id field. If not, give it a value. Actually, give it a value anyway
  2. Right but it's throwing the error for the class.phpmailer.php I try to include, not a file it subsequently tries to include. Full error text: Warning: require_once(../lib/class.phpmailer.php) [function.require-once]: failed to open stream: No such file or directory in /home/danny/workspace/smswebalerts/inc/send_email.php on line 3 Fatal error: require_once() [function.require]: Failed opening required '../lib/class.phpmailer.php' (include_path='.:/opt/lampp/lib/php') in /home/danny/workspace/smswebalerts/inc/send_email.php on line 3
  3. Not all email clients support HTML emails. Most modern ones do, though. I'm not 100% sure but I think a special property has to be set to flag the email as containing HTML otherwise it won't be parsed. I'm not sure how to do it off the top of my head, though
  4. I was under the impression this was a simple thing to do and I'm fairly certain I've done it before, but it isn't working for some reason. Under the root directory of my project I have two subfolders called "inc" and "lib". lib contains third-party scripts for use in my project. The one in question is phpmailer (lib/class.phpmailer.php). Now, in inc I have a file that needs to include PHPMailer. Inside my script in inc I have this: require_once('../lib/class.phpmailer.php'); It errors out saying it can't find it. I thought that was supposed to go down one directory then back up into lib. The file does indeed exist. What am I doing wrong? This seems like a stupidly simple thing...
  5. With DOMPDF what you need to do is send the output to a temp file instead of streaming it to the user (I don't recall exactly how to do that but I'm fairly certain it's possible) then email that temp file to the user. As far as I know the mail() function does not support attachments so you'd have to look into another library for email.
  6. I can definitely see that being true. Like you said I have my own "framework" type stuff where I use the same techniques and patterns in almost all my projects to streamline things. I guess I'm re-inventing the wheel, except my wheel is kinda lopsided and doesn't roll as well. What makes me the most apprehensive is that I already have so many projects, including an ever growing piece of software at work, already written using my current methods. I don't know if it's worth it to stop, learn a framework, and convert some of my bigger stuff over to the framework.
  7. I don't know if you have access to the logs with your hosting provider but normally a log entry is created in the syslog (or cron.log if you've configured it to do so). And you should be able to change your file as much as you want. The crontab just "points" to it, it doesn't cache the contents anywhere so it always runs what's there when it executes.
  8. I'm really hung up here. I watched some videos about CodeIgniter, and it seems nice and I can definitely see the advantages but it's also such a drastic change from what I'm used to. I'm not a PHP guru or anything but I do well enough. I have tons of scripts and several applications written in PHP for my job, plus a zillion half-finished personal projects. Would it be worth the effort for me to take the time to learn the ins and outs of a framework and start using it? Is there anything "wrong" with doing everything the "old fashioned" way?
  9. Well from a functional standpoint the browsers render it correctly, but as I recall from doing this in the past, it won't validate like that. It seems to complain about this or that tag not being allowed inside a form. Maybe I'm just remembering wrong...
  10. Or is it all pieced together into one file then executed? I ask because I'm thinking of a weird way to handle errors on my site that would integrate with the interface smoothly without much work on my part. Every page on my site requires template_top.php at the start of the script and template_bottom.php at the bottom. I believe this is a pretty common thing to do, and it standardizes all my menus and interfaces and whatever else, plus it gives me a nice place to deliver messages to the user. What I want to do is something like this simplified example: template_top.php: <?php // layout stuff here try { ?> index.php: <?php require_once('template_top.php'); // a wild error appears! throw new Exception('oh no!'); require_once('template_bottom.php'); ?> template_bottom.php: <?php } catch (Exception $e) { echo 'An error occured! Message: ' . $e->getMessage(); } // layout stuff here ?> So that's where my question comes in. Both template files contain code that, if executed on it's own, is invalid. Pieced together in my pages though, it forms correct code. I'd really like to do this since all I'd have to do if my script encounters a problem is throw an Exception and everything is instantly handled without me having to fight with display issues. If this isn't possible, does anybody have any better suggestions?
  11. I'm making a settings page. The settings are divided into groups with other page content in-between. I want to have one single "save" button on the bottom that submits my form. Now, I know it's not technically valid HTML to just open a form tag at the top of my page, output all my content, then close it at the bottom. I was hoping that giving them all the same name would do it but apparently not. This is what I tried: <form name="test" method="get"> <input type="text" name="test1" /> </form> blah blah blah content here <form name="test" method="get"> <input type="text" name="test2" /> <input type="submit" /> </form> When the form is submitted, only values in the same form tag as the submit button get sent, so in this example test2 gets submitted but not test1 How should I design this?
  12. Well it's not quite that simple. You'll have to make another page, assuming you don't have one. In my example, viewrace.php would be what you create. GET variables are the extra stuff you see in the URL after your page name like viewrace.php?id=1&hello=world . Everything past the ? is a GET variable. They can be put there by a form with it's method set to GET, or manually like I did in my example. In viewrace.php, you could now access the variables set in the URL like so: echo $_GET['id']; // Outputs "1" echo $_GET['hello']; // Outputs "world" Knowing that, you can make a viewrace.php which takes the 'date' GET variable and queries the database for all races with the same date as $_GET['date'] then display them like you've already done. Also I made a slight omission in my example. The line: <td><a href=\"viewrace.php?date={$row['racedate']}\">{$row['racedate']}</a></td> should be changed to <td><a href=\"viewrace.php?date=" . urlencode($row['racedate']) . "\">{$row['racedate']}</a></td> That adds a call to urlencode() which will make it possible to pass special characters through the URL (like date separators). That's just a basic overview of the concept. There's still a lot more to learn to make a "better" system (like user input cleanup/security primarily) but that's the basic idea.
  13. For some reason my mind is blanking and I can't stay focused long enough to think why that isn't working but personally I would suggest doing it a little differently. You probably don't need to tell the user which part of their login details are wrong. This potentially gives an attacker a bit more information since your script will essentially tell them they have a correct username. It's certainly not a big security risk but there's really not any reason to give out the extra information. Just withholding which part of their login details are incorrect exponentially multiplies the complexity of doing a blind brute force attack (although you should take steps other than this to guard against that). Instead of what you're trying to do, have you considered just doing something like setting $hasErrors or whatever to true, then in place of your current code having if($hasErrors) echo 'Invalid username and/or password';
  14. There's a closing ) missing after ("user") on the second line. Although I don't see why you're surrounding your strings with parenthesis anyway, it should work just fine without. Parenthesis are generally used to change the order of operations which you don't need to do with just one comparison.
  15. You can use standard HTML techniques to do what you desire. The table part is easy, but I'm not sure how your site is set up so it's a bit hard for me to say exactly what your link needs to look like but here's my modification to your code to get you started: $i = 1; echo '<table border="1"><tr><th>Num</th><th>Placing</th><th>Race Date</th><th>Horse ID</th></tr>'; while ($row = mysql_fetch_assoc($searchResult)) { echo "<tr><td>$i</td> <td>{$row['placing']}</td> <td><a href=\"viewrace.php?date={$row['racedate']}\">{$row['racedate']}</a></td> <td>{$row['horseid']}</td></tr>"; $i++; } echo '</table>'; That should display your results in a table. Modify it to look how you want. As it is now, if the user clicks on the race date it will take them to a "viewrace.php" page with the date passed in as a $_GET variable so that page could take that date and query for races on that date. Obviously since I don't know your site structure you'll have to adjust that, I'm just showing how it could work.
  16. Do you have a field storing a timestamp for when a thread's last post was? If so you could just use an ORDER BY clause like this simplified example: SELECT threadname, author FROM threads WHERE board_id=2 ORDER BY last_post DESC The DESC makes it sort backwards (higher to lower instead of visa-versa). Since a more recent timestamp will be larger, the query results will be ordered by post time from newest to oldest, at which point you can loop and display as normal and they will be sorted. If you don't have a "last post" type field associated with your thread and only store the timestamp with the post itself you could probably do something involving a join but joins hurt my brain and I've been doing way too much repetitive work today to provide you with a clear example of that.
  17. If I'm understanding your question correctly you should be able to change the second "if" to an "elseif"
  18. I just want to check if a row exists, I don't need to actually pull down any data. Right now I'm doing it like this: SELECT id FROM dbase WHERE id=$id After running that query I use mysql_num_rows to make sure it returned exactly one row, in which case I know the ID the user passed is valid. This isn't a big issue but for the sake of code readability I'd like to do something like this instead: SELECT NOTHING FROM dbase WHERE id=$id Is something like that possible?
  19. Your update syntax is wrong. "AND" is used to chain together conditional statements in the WHERE clause. Proper format would be something like: UPDATE mytable SET field1='hello', field2='world', field3=42 WHERE id=20 AND age >= 50 EDIT: Also worth mentioning is that your code is left wide open to SQL injection attacks. Never insert user data directly into a query (the POST variables in your example). What if instead of their name they put in "'; DROP TABLE users" or something destructive like that? Your code would happily follow along and destroy the database. Do something like this instead: $name = mysql_real_escape_string($_POST['name']); Then use $name in your query instead of $_POST['name']
  20. Yeah I cannot understand what he's asking either... dwex, would you mind providing us with the code that contains your problem and perhaps restate your question clearer?
  21. Can you be more specific about what you mean when you say you're "executing" script.php? Are you navigating to it through the web browser or calling it on the command line with something like "php -f script.php"? As for "rewriting" the page in PHP, that isn't necessary. In a PHP document, any HTML outside of the opening and closing PHP tags will get sent as normal, only PHP inside those tags will be executed.
  22. You might want to look into the dompdf library: http://www.digitaljunkies.ca/dompdf/ It takes HTML and converts it into a PDF document. I used it when making my report system at work and it has worked very well for us. You could use it to generate a temporary PDF file and then use another library like phpmailer ( http://phpmailer.worxware.com/ ) to send that temp file as an attachment. It can be a bit finicky, especially if you use advanced CSS but overall it does a good job and they have a google group set up to provide support for it.
  23. I'm pretty sure every single beginning PHP coder has been confused by "paamayim nekudotayim" at some point or another. Is isn't exactly the most self explanatory terminology ever (unless you speak Hebrew I guess).
  24. Do you have Apache (or substitute whatever web server you're using if not apache) and PHP properly configured on the machine you're trying to execute? What happens when you view script.php in your web browser? Does it give any sort of error or does it just output the PHP code? There's nothing wrong with your code syntax wise (although it's a bit redundant, you don't need 3 echos), so assuming apache and PHP are configured correctly and the script is in one of the folders apache serves up it should be working fine. EDIT: Actually the above post made me realize I might be reading the OP incorrectly. If "script.php" and the document the code you posted are in different files then yes, any file with PHP to be executed needs to have a .php extension as he said. It's actually possible to make PHP execute code in files with other extensions but it goes against the "standard" and I would not recommend doing this unless you A. are the administrator of the server you plan to run this on and B. do not intent to distribute code to other users.
  25. I don't believe there's any way to do specifically what you're trying to do here. This is one of those problems that needs to be solved by better design rather than more features.
×
×
  • 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.