Jump to content

bradkenyon

Members
  • Posts

    179
  • Joined

  • Last visited

    Never

Everything posted by bradkenyon

  1. I have a page that allows you to update entries, but it checks to make sure you're the author of that entry. <?php $id = $_GET['id']; $author = $HTTP_SESSION_VARS['valid_username']; $sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '$author'"; if($result = mysql_query($sql)) { if(mysql_num_rows($result)) { if(!$_POST) { $queryupd = "select * from calendar_items where id = $id"; $resultupd=mysql_query($queryupd); ?> <div class="details"> <?php while($rowupd = mysql_fetch_array($resultupd)) { ?> <form enctype="multipart/form-data" method="post" action="<?=$_SERVER["PHP_SELF"]?>"> <?php print '<input type="hidden" name="id" value="'.$rowupd['id'].'">'; print '<h3>Event Title</h3>'; print '<input type="text" name="subj" size="60" value="'.htmlentities($rowupd['subj']).'">'; print '<p><input type="Submit" value="Submit" name="Submit"> <a href="/cms/">Cancel</a> </form>'; } } else { $id=$HTTP_POST_VARS['id']; $subj=addslashes($HTTP_POST_VARS['subj']); $result = mysql_query("UPDATE calendar_items SET subj='$subj' WHERE id=$id") or die(mysql_error()); } } else { // display your unauthorised message print ' <div class="alert"> To update, you need to be author of event. </div>'; } } ?> When I hit submit, it does not work. I think the if(!$_POST) might be the problem. The way it should work: if the form was not posted, then display the form w/ the current data, if it was posted, then grab the values within the form fields and update them in the db table, then display the form w/ the updated values.
  2. Stupid me put the format of the datetime as 2008-08-22 09:17:00 it should be 20080822091700 So $today = 2008-08-22 and it checks the year-month-day part of the expiredate, which does the trick. next time i'll format it correctly.
  3. hope this is what you're referring to. [attachment deleted by admin]
  4. I have the expiredate in this format: 2008-09-05 20:00:00 I am guessing I should of put it in like this? 20080905200000
  5. this is what I have, I have an event for today: 2008-08-20, and it does not display it, but if I have this $query = "select * from upcomingevents WHERE expiredate LIKE '$today %'"; , it does. and this does not: <?php $query = "SELECT * FROM upcomingevents WHERE DATE(expiredate) = CURDATE()"; $result=mysql_query($query); if($result) { ?> <ul> <?php while($row = mysql_fetch_array($result)) { $i = 0; $t = 1; while($i <=0) { print '<p><strong>'.date("l F j, Y",strtotime($row['expiredate'])).'</strong> - <a href="/events/?id='.$row['id'].'">'.$row['subj'].'</a> - <small>'.$row['location'].'</small></p>'; //$message.= date("m/d/y",strtotime($row['expiredate']))."\t".$row['subj']."\t".$row['location']."\r\t\t".$row['body']."\r\r"; $message.= ''.date("l F j, Y",strtotime($row['expiredate']))."\r\r\t".$row['subj']."\r\t".$row['location']."\r\t".$row['body']."\r---------------------------------------------------------------------------------------------------------\r\r"; $i++; $t++; } } $email = 'no-reply@domain.com'; $mail = new htmlMimeMail(); $mail->setText($message); $mail->setSubject('Faculty/Staff Events'); /** * Sends the message. */ $mail->setFrom($email); $result = $mail->send(array('email@email.com')); //echo $result ? 'Mail sent!' : 'Failed to send mail'; ?>
  6. I need to check for YYYY-MM-DD of expiredate and current date, and not factor in the hour, min, secs. This seems to not work: SELECT * FROM upcomingevents WHERE DATE(expiredate) = CURDATE() I was thinking this may do it, but it did not: SELECT * FROM upcomingevents WHERE DATE(expiredate, '%Y-%m-%d') = DATE_FORMAT(CURDATE(),'%Y-%m-%d')
  7. $query = "select * from upcomingevents WHERE expiredate LIKE '$today %'"; w/ $today being today's date like YYYY-MM-DD Looks like it is working. I would like to know if there might be a case in which this may not. Thanks.
  8. I need a query that will only pull today's events out of the db table. I have a field that stores dates, titled: expiredate for example, an event that i want to display today has a expiredate of: 2008-08-19 19:21:00 I just want it to check for 2008-08-19 So any events w/ a expiredate of 2008-08-19 will be displayed. Obviously it will check for 2008-08-20 tomorrow, so I just want the query to check for the event's YYYY-MM-DD and if it is equal to the current YYYY-MM-DD, then pull it. I was thinking of something like. SELECT * table WHERE expiredate(YYYY-MM-DD) = CURDATE(YYYY-MM-DD) The above query is literal, so you can see what I am trying to achieve. Any help is appreciated. Thanks.
  9. no, but i just pulled it up, looks interesting. thanks for the suggestion.
  10. Thanks for the help. Maybe there is a little more to my problem than I thought, here is all the code for what I am trying to accomplish, to only display the events on Monday thru Friday, so I only want to display events for 8/11 - 8/15 of this week (think of NOW() as 8/11). Something must be funny w/ the while loops, because it displays all events that are not past due, and I want it to show events only up till the end of 8/15. <?php require_once("../customemailer/htmlMimeMail.php"); include('../cgi-bin/newsinclude/db.php'); $query = "SELECT * FROM upcomingevents WHERE expiredate > DATE_ADD(NOW(), INTERVAL 5 DAY) ORDER BY expiredate"; $result=mysql_query($query); if($result) { ?> <ul> <? while($row = mysql_fetch_array($result)) { $i = 0; $t = 1; while($i <=0) { print '<p><strong>'.date("l F j, Y",strtotime($row['expiredate'])).'</strong> - <a href="/events/?id='.$row['id'].'">'.$row['subj'].'</a> - <small>'.$row['location'].'</small></p>'; //$message.= date("m/d/y",strtotime($row['expiredate']))."\t".$row['subj']."\t".$row['location']."\r\t\t".$row['body']."\r\r"; $message.= ''.date("l F j, Y",strtotime($row['expiredate']))."\r\r\t".$row['subj']."\r\t".$row['location']."\r\t".$row['body']."\r---------------------------------------------------------------------------------------------------------\r\r"; $i++; $t++; } } $email = 'no-reply@domain.com'; $mail = new htmlMimeMail(); $mail->setText($message); $mail->setSubject('Faculty/Staff Events'); /** * Sends the message. */ $mail->setFrom($email); //$result = $mail->send(array('email@address.com')); //echo $result ? 'Mail sent!' : 'Failed to send mail'; } else { print 'There are no events.'; } ?>
  11. I plan on setting up a script that is run on the server every Monday morning at 8am. I want to only send the events that are within that week. So I was thinking for pulling the appropriate events from the table, I would do this: SELECT * FROM upcomingevents WHERE expiredate > NOW() + 5 days ORDER BY expiredate Obviously the + 5 days part is being literal, how would I go about adding 5 days to it, meaning I want to send all events that are taking place between Monday 8am to Friday 11:59pm of that week?
  12. I have this code that adds email addresses to a table, and I want to check to see if the email address is already in the table, how would I go about that w/ the current code? Any help is appreciated. include('db.php'); if($_POST) { $fname=$HTTP_POST_VARS['fname']; $lname=$HTTP_POST_VARS['lname']; $email=$HTTP_POST_VARS['email']; $query = mysql_query("INSERT INTO maillist (fname, lname, email) VALUES('$fname', '$lname', '$email')"); result - mysql_query($query); if($result) echo mysql_affected_rows().' maillist inserted into database.'; ?> <h2 align="center">Thank You for signing up, you'll now receive festival updates!</h2> <? } else { ?> <span class="heading">Sign Up</span> <p> <form method="post" action="<?=$_SERVER["PHP_SELF"]?>"> <table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#CAD7BB"> <tr> <td><strong>Email:</strong></td> <td><input type="text" name="email"></td> </tr> <tr> <td><strong>First Name:</strong></td> <td><input type="text" name="fname"></td> </tr> <tr> <td><strong>Last Name:</strong></td> <td><input type="text" name="lname"></td> </tr> <tr> <td colspan="2"><input type="Submit" name="Submit" value="Submit"></td> </tr> </table> <? } ?>
  13. @thorpe: Your sql query did the trick, and I made a modification to the update process, only allowing the original author to make an update to their original post. here is the other post (i think you might have a good idea what might be going wrong) i opened up for help, any help would be appreciated. http://www.phpfreaks.com/forums/index.php/topic,211395.0.html
  14. craps out when i hit submit, so i feel like the if statement for checking if it was posted within the two other if statements to check the query results is messing it up, because if i remove those the test for checking to see if it is the correct author to update the entry, it works. but i need that check, to make sure the person making the update is the appropriate person, if they are not, their update won't be approved (by approved, i mean the data they try submitting will not be entered into the db table in place of the original).
  15. thanks for the suggestion, tried, no luck. I think it has something to w/ this part of the code: if($result = mysql_query($sql)) { if(mysql_num_rows($result)) {
  16. Below I am trying to update values in a db table, which are plugged into an update form, to be updated. Once I hit submit, it doesn't update. I know connecting to the db is not a problem, I feel like the problem is something w/ the if statement of the if(!$_POST) and the one above that: if(mysql_num_rows($result)) and possibly if($result = mysql_query($sql)). It seems like it ignores this part all together after hitting submit: else { $id=$HTTP_POST_VARS['id']; $subj=addslashes($HTTP_POST_VARS['subj']); $result = mysql_query("UPDATE calendar_items SET subj='$subj' WHERE id=$id") or die(mysql_error()); } <?php $id = $_GET['id']; $author = $HTTP_SESSION_VARS['valid_username']; $sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '$author'"; if ($result = mysql_query($sql)) { if(mysql_num_rows($result)) { // do the update if(!$_POST) { $queryupd = "select * from calendar_items where id = $id"; $resultupd=mysql_query($queryupd); ?> <div class="details"> <?php while($rowupd = mysql_fetch_array($resultupd)) { ?> <form enctype="multipart/form-data" method="post" action="<?=$_SERVER["PHP_SELF"]?>"> <?php print '<input type="hidden" name="id" value="'.$rowupd['id'].'">'; print '<h3>Event Title</h3>'; print '<input type="text" name="subj" size="60" value="'.htmlentities($rowupd['subj']).'">'; print '<p><input type="Submit" value="Submit" name="Submit"> <a href="/cms/">Cancel</a> </form>'; } } else { $id=$HTTP_POST_VARS['id']; $subj=addslashes($HTTP_POST_VARS['subj']); $result = mysql_query("UPDATE calendar_items SET subj='$subj' WHERE id=$id") or die(mysql_error()); } } else { // display your unauthorised message print ' <div class="alert"> To update, you need to be author of event. </div>'; } } ?> Any help is appreciated, thank you.
  17. currently it is: $sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '{$_SESSION['valid_username']}'"; would it be? $sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '{$_SESSION['valid_username']}' AND user_level = '1'"; user_level being a super user account.
  18. can i throw a conditional into if(mysql_num_rows($result)), so I can set a certain user or certain user_level to access all, and not just ones that match the author?
  19. I have an rtf file, well, multiple rtf's files that I want the php code to read and display on the webpage as html, or maybe display it as <pre>rtf file content</pre> What is a good way to go about this? Any help is appreciated.
  20. I am using this php script to detect mobile browsers: http://www.andymoore.info/php-to-detect-mobile-phones/ I include the script at the top of the page, then do the if statement he used in the example, but when I view the page on a normal web browser, it shows nothing. Could someone help me out w/ what I might be doing wrong? Thanks. <?php include('mobile_detect.php'); if(detect_mobile_device()) { header('Location: http://m.domain.com/'); exit; } else { //normal website html } ?>
  21. thanks for the explanation. how would i set a variable to count up as each line is printed, setting the running tally to each accesskey of each line. so it will be... <li accesskey="1">content</li> <li accesskey="2">content</li> <li accesskey="3">content</li> <li accesskey="4">content</li> <li accesskey="5">content</li> <li accesskey="6">content</li>
  22. I have this code below that I want to run an index for accesskey, to it goes 1 thru 8, and for each line item, i want it to number the accesskey accordingly, for example. <li accesskey="1">content</li> <li accesskey="1">content</li> so on and so forth... this is the code i have for it, but it just spits out 0 for each accesskey <? include('db.php'); $query = "SELECT * FROM news ORDER BY tstamp DESC LIMIT 8"; $result=mysql_query($query); ?> <ol> <? while($row = mysql_fetch_array($result)) { $i = 0; $t = 1; while($i <=0) { print '<li accesskey="'.$i.'"><a href="/news/?id='.$row['id'].'">'.$row['subj'].'</a></li>'; $i++; $t++; } } ?> </ol>
  23. still not working. today there is an event, but it doesn't send anything, today's event expiredate is: 2008-07-10 11:35:00 here is all the code. <?php require_once("../customemailer/htmlMimeMail.php"); include('../cgi-bin/newsinclude/db.php'); //date("m/d/y",strtotime($row['expiredate']) $query = "SELECT * FROM calendar_items WHERE DATE(expiredate) = CURDATE()"; //$query = "SELECT * FROM calendar_items WHERE expiredate > NOW() ORDER BY expiredate"; $result=mysql_query($query); if($result) { ?> <ul> <? while($row = mysql_fetch_array($result)) { $i = 0; $t = 1; while($i <=0) { print '<p><strong>'.date("m/d/y",strtotime($row['expiredate'])).'</strong> - <a href="/events/?id='.$row['id'].'">'.$row['subj'].'</a> - <small>'.$row['location'].'</small></p>'; //$message.= date("m/d/y",strtotime($row['expiredate']))."\t".$row['subj']."\t".$row['location']."\r\t\t".$row['body']."\r\r"; $message.= $row['subj']."\t".$row['location']."\r".$row['body']."\r---------------------------------------------------------------------------------------------------------\r\r"; $i++; $t++; } } $email = 'no-reply@domain.com'; $mail = new htmlMimeMail(); $mail->setText($message); $mail->setSubject('Faculty/Staff Events'); /** * Sends the message. */ $mail->setFrom($email); $result = $mail->send(array('morsebk@herkimer.edu')); //echo $result ? 'Mail sent!' : 'Failed to send mail'; } else { print 'There are no events.'; } ?>
×
×
  • 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.