Jump to content

mbrown

Members
  • Posts

    154
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

mbrown's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. I was corrected on the global. That has been removed. What is going on with this code is that it is a mailing function.
  2. 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 ?>
  3. 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
  4. 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"); ?>
  5. <?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?
  6. Thanks Jacques1! then I could do the conditional if $voteCount == $usercount ?
  7. 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.
  8. $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?
  9. 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.
  10. The echo runs but the INSERT does not actually run. I have my my sql server running everything and the INSERT is not executing.
  11. 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"; } ?>
  12. 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?
  13. 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.
  14. 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.
×
×
  • 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.