Jump to content

mbrown

Members
  • Posts

    154
  • Joined

  • Last visited

Everything posted by mbrown

  1. I am trying to find examples of code for calendars that have the hours like amusement parks use https://www.dutchwonderland.com/hours-and-directions/hours-and-schedule that is one example
  2. I was curious to see if anyone has used LDAP with their PHP application. If you have what benefits does it provide over using a MySQL database? I am looking at expanding my knowledge of using PHP with various authentication services. I am not sure if this is in the right forum, if so please move it to the appropriate one.
  3. Thank you for your response Jacques. I will look into that. I have msmtp set up to be used by mail so that I can authenicate to gmail to send emails.
  4. It still does not work via the application. It is saying "msmtp: no recipients found"
  5. I changed to the following code and it seems to work some times. $headers .= "From: Tanyard Springs Votes <noreply@tanyardspringshoa.com>\r\n"; //mailing if (mail($boardEmail,$subject,$message,$headers)) print "Email successfully sent"; else print "An error occured"; }//end of function addmailing(52);
  6. So when I run the following command on the command line the mail is sent without issue echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" | msmtp --debug -a gmail mike.a.brown09@gmail.com --file=/etc/.msmtp_php Nothing is showing up in /var/log/msmtp.log or /var/log/mail.log file I now have the following in a file called test.php <?php if(mail("michaelbrown.tsbod@gmail.com","A Subject Here","Hi there,\nThis email was sent using PHP's mail function.")) print "Email successfully sent"; else print "An error occured"; ?> The /var/log/msmtp.log file shows the following: So both the echo statement and the going to test.php work fine and send the email. But when I have following code and run mail it does not work: <?php include_once('include/db-config.php'); function addmailing($votesmotionid) { global $db_con; $motionArray = array($votesmotionid); $userSearch=$db_con->prepare("SELECT * from users where enabled=1;"); $userSearch->execute(); foreach ($motionArray as $motionid) { while ($row=$userSearch->fetch(PDO::FETCH_ASSOC)) { $firstName = $row['first_name']; $lastName = $row['last_name'] ; $name="$firstName $lastName"; } $motion=$db_con->prepare ("SELECT * from motions where motion_id = :motionid"); $motion->bindParam(':motionid',$motionid); if (!$motion->execute()) var_dump($motion->errorinfo()); $body="<html> <head> <title>New Motion Addded</title> </head> <body>"; $body .= "Dear $name <br /><br />"; $body .= "A new electronic vote has been created, please review it as soon as possible. The information is below."; while ($row=$motion->fetch(PDO::FETCH_ASSOC)) { $motionid=$row['motion_id']; $motionname=$row['motion_name']; $dateadded=$row['dateadded']; $motiondesc=$row['motion_description']; $body .= "<br ><br />Motion ID: " . $motionid; $body .= "<br />Motion Name: " . $motionname; $body .= "<br />Date Added: " . $dateadded; $body .= "<br />Motion Text: " . $motiondesc; }//End of while $body .= "</body> </html>"; }//end of foreach $boardEmail = ""; $emailSearch=$db_con->prepare("SELECT * FROM users where enabled=1"); $emailSearch->execute(); while ($row=$emailSearch->fetch(PDO::FETCH_ASSOC)) { $boardEmail .= $row['email'] .","; } $subject = "New Motion " . $motionid; echo "Board Email: " . $boardEmail; $message = $body; $headers = ""; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "To: $boardEmail\r\n"; $headers .= "From: Tanyard Springs Votes <noreply@tanyardspringshoa.com>\r\n"; //mailing mail($boardEmail,$subject,$message,$headers); }//end of function addmailing(52); Any help determining what is the issue would be greatly appreciated. The code base in the last example is rough code which will be fixed once I have this mail issue resolved.
  7. I was corrected on the global. That has been removed. What is going on with this code is that it is a mailing function.
  8. I am getting an error in my following code. The error is This would make it on the this line: global $body .= "<h1>" . $motionname . "</h1> <?php function mailing($motionid) { $motionArray = array($motionid); foreach ($motionArray as $motion) { //Database Connection include_once ('include/db-config.php'); $motion=$db_con->prepare ("SELECT * from motions where motion_id = :motionid"); $motion->bindParam(':motionid',$motionid); $motion->execute(); $body="<html> <head> <title>Status of Motion</title> </head> <body>"; while ($row=$motion->fetch(PDO::FETCH_ASSOC)) { $motionid=$row['motion_id']; $motionname=$row['motion_name']; $dateadded=$row['dateadded']; $motiondesc=$row['motion_description']; $disposition=$row['motion_disposition']; global $body .= "<h1>" . $motionname . "</h1> <h2>Date Added:</h2>" . $dateadded . "<br /> <h2>Motion Text</h2>" . $motiondesc; "<h2>Disposition:</h2>" . $disposition; }//End of while global $body .= "<br /><br /> <h2>Current Votes</h2> <table border=\"1\" width=\"100%\"> <tr> <th>User</th> <th>Date</th> <th>Vote</th> </tr>"; $votes=$db_con->prepare( "SELECT u.first_name, u.last_name, v.time, v.vote from votes v inner join motions m on m.motion_id=v.motions_id INNER join users u on u.users_id=v.users_id where m.motion_id=:motionid ORDER BY v.time ASC;"); $votes->bindParam(':motionid',$motionid); $votes->execute(); while ($row=$votes->fetch(PDO::FETCH_ASSOC)) { $firstname=$row['first_name']; $lastname=$row['last_name']; $votetime=$row['time']; $votecast=$row['vote']; global $body .= "<tr> <td>" . $firstname . " " . $lastname . "</td> <td>" . $votetime . "</td> <td>" . $votecast . "</td> </tr>"; }// while ($row=$votes->fetch(PDO::FETCH_ASSOC)) global $body .= "</table>"; global $body .= "<br /><br /> <h2>Discussions</h2> <table border=\"1\" width=\"1\"> <tr> <th>User</th> <th>Date</th> <th>Comment</th> </tr>"; $motiondiscussions=$db_con->prepare( "SELECT u.first_name,u.last_name,d.dateadded,d.discussion_text from users u inner join discussion d on d.user_id=u.users_id where d.motion_id=:motionid"); $motiondiscussions->bindParam(':motionid',$motionid); $motiondiscussions->execute(); while ($row=$motiondiscussions->fetch(PDO::FETCH_ASSOC)) { $firstname=$row['first_name']; $lastname=$row['last_name']; $discussiontime=$row['dateadded']; $discussiontext=$row['discussion_text']; global $body .= "<tr> <td>" . $firstname . " " . $lastname . "</td> <td>" . $discussiontime . "</td> <td>" . $discussiontext . "</td> </tr>"; }//end of while global $body .= "</table>"; global $body .= "</body> </html>"; }//end of foreach $email="michaelbrown.tsbod@gmail.com"; $to="michaelbrown.tsbod@gmail.com"; $subject = "Summary for Motion " . $motionid; $message = $body; $headers[] = 'MIME-Version: 1.0'; $headers[] = 'Content-type: text/html; charset=iso-8859-1'; $headers[] = 'To: Michael Brown <michaelbrown.tsbod@gmail.com>'; $headers[]= 'From: Tanyard Springs Votes <noreply@tanyardspringshoa.com>'; //mailing mail($to,$subject,$message, implode("\r\n", $headers)); }//end of function ?>
  9. Thanks pyscho. Again I have only given part of the code. I did not think about it. I can easily update the SQL to do things like that. Thanks again
  10. I see I could do it something like this too <?php /* Delete all rows from the FRUIT table */ $del = $dbh->prepare('DELETE FROM fruit'); $del->execute(); /* Return number of rows that were deleted */ print("Return number of rows that were deleted:\n"); $count = $del->rowCount(); print("Deleted $count rows.\n"); ?>
  11. <?php $userCount = $db_con->query('SELECT COUNT(*) FROM users WHERE enabled=1')->fetchColumn(); $userCount -> execute(); $voteCountStmt = $db_con->prepare('SELECT COUNT(*) FROM votes WHERE motions_id = :motionid'); $voteCountStmt->execute(['motionid' => $motionid]); $voteCount = $voteCountStmt->fetchColumn(); if ($voteCount == $ $userCount) { //Update Final Disposition to PASSED } else { exit; } So something like the above?
  12. Thanks Jacques1! then I could do the conditional if $voteCount == $usercount ?
  13. I have printed out the count from both. The rows got inserted when a person votes on a motion. Based on Jacques1 reply it could be because I am using an incorrect function for what I want. Thank you for this information. That being said, I will do some research to identify what I need to do to count rows not columns. The second query may not always be one. It could be anything between 0 and 5 depending on how many people have voted on it. I need this to determine when we can set the motion_disposition column to PASSED in the motions table.
  14. $enabledCount=$db_con->prepare( "SELECT * FROM users where enabled=1;"); $enabledCount->execute(); $row=$enabledCount->fetchAll(PDO::FETCH_ASSOC); $usercount=count($row); $votecount=$db_con->prepare( "SELECT * FROM votes where motions_id=:motionid"); $votecount->bindParam(':motionid',$motionid); $votecount->execute(); $voterow=$votecount->fetch(PDO::FETCH_ASSOC); $votecount=count($voterow); My code is above. The first one should return 5 but the second one should only return one. What am I missing?
  15. Thank you jacques. That is the plan moving forward. I got alot of the functionality out there so we could start using the system. I have all ready created a bug in our bug tracking system to make sure that everything is handled like you explained with the PDO exceptions. I can not believe that I did not code those in since day 1. Again Thank you for your advise. If I do it this way then I could still use the bind parameter lines to set up those variables correct? When I was in school we used mysqli which I know is outdated now so this is my first attempt using PDO. Like Jacques1 stated, the code was not fine and that the syntax was incorrect. That is what I get for doing it while I was tired.
  16. The echo runs but the INSERT does not actually run. I have my my sql server running everything and the INSERT is not executing.
  17. I am not having fun with this code this evening. What am I missing? I know I am tired but still. Any help would be great! <?php include_once ('include/db-config.php'); #Debug: echo $_SERVER['HTTP_REFERER']; $motionid=$_POST['motionid']; $userid=$_POST['userid']; $text=$_POST['discussiontext']; #echo "Motion ID: " . $motionid . "<br />User ID: " . $userid . "<br />Text: " . $text . "<br />"; if ( strlen($text) == 0 ) { echo "You have not entered any text"; } else { $addDiscussion=$db_con->prepare( "INSERT INTO discussion (user_id,motion_id,discussion_text) VALUES(:userid, :motionid, :text"); $addDiscussion->bindParam(':userid',$userid); $addDiscussion->bindParam(':motionid',$motionid); $addDiscussion->bindParam(':text',$text); $addDiscussion->execute(); echo "Added Discussion Text"; } ?>
  18. Jaques1 thank you for the quick response. I see what you are saying. So what I want to do is provide the a list of all motions and they will choose one to vote on. What would be the best way to do this? Would it better to make each row a form and have a submit button for each row?
  19. So I have following code <p>Please choose a motion to vote on. Only one motion can be voted on at a time</p> <form id="vote" action="voting.php" method="post"> <table border="1" width="100%"> <tr> <th>Select</th> <th>Motion Text</th> <th>Date Added</th> </tr> <?php include_once ('include/db-config.php'); $motions=$db_con->prepare( "select * from motions where motion_disposition is NULL"); $motions->execute(); while ( $row = $motions->fetch(PDO::FETCH_ASSOC)) { ?> <tr> <td><input type="radio" name="<?php $row['motion_id']?>" id="<?php $row['motion_id']?>" value="<?php $row['motion_id']?>"</td> <td><?php echo $row['motion_name']; ?> </td> <td><?php echo $row['dateadded']; ?> </td> </tr> <?php }//end of while ?> </table> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> When it goes to the page nothing is sent over when I print the $_POST array. I know I am missing something small but I can not put my finger on it Any help would be much appreciated.
  20. The user_id is a integer. ERROR REPORTING set to all DISPLAY ERRORS is enabled I am seeing it now. Not sure why it did not show up before. Thanks for the reminder about error reporting and display errors. That will help me out alot in the future in development.
  21. All right. I have it tested with the userid as shown above in the example. Nothing is printed out. I am currently in the session and nothing.
  22. Thanks. Can you give me an example of the debug message you are speaking of?
  23. <?php session_start(); if(empty($_SESSION['user_id'])){ header('location: index.php'); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Main Dashboard</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/bootstrap-responsive.min.css" rel="stylesheet"> <link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600" rel="stylesheet"> <link href="css/font-awesome.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet"> <link href="css/pages/dashboard.css" rel="stylesheet"> <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <?php $userid=$_SESSION['user_id']; echo $userid; ?> I have the above code. I am curious why I can not print out the userid on the page. I am using this as a roadmap as I want to include the username, first and last name in the session variables so I can use it throughout the current session to write out something like "Welcome First_Name Last_Name" Thanks for the help! Mike
  24. Thanks Jacques. Just create the necessary php and let cronjob run it?
×
×
  • 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.