Jump to content

mbrown

Members
  • Posts

    154
  • Joined

  • Last visited

Posts posted by mbrown

  1. I am getting an error in my following code. The error is 

     

     

    PHP Parse error:  syntax error, unexpected '.=' (T_CONCAT_EQUAL), expecting ',' or ';' in /var/www/html/board/mail.php on line 25

     

    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
    ?>
    
  2.  

    I'm making some assumptions here, but I would think that a vote should indicate a vote for or against the issue. But, your logic seems to imply that votes are only to indicate a "for" vote and all users must for for in order for it to pass. That seems like odd logic. Even if a unanimous decision is required, you should have some allowance for when someone doesn't cast a vote.

     

    Plus, you can easily determine 1) How many voters there are, 2) How many users have votes, and 3) The results of the vote with a single query. You don't state whether the votes table has an identifier for the user who casts a vote - but it should.

     

    Query

    SELECT COUNT(u.user_id) as users,
           COUNT(v.vote_id) as votes,
           (COUNT(u.user_id)=COUNT(v.vote_id)) as passed
    FROM votes v
    RIGHT JOIN users u
      ON  v.user_id = u.user_id
      AND v.motion_id = :motion_id

    Results would look something like this (3 of 5 users have voted)

    users | votes | passed
      5       3        0

    Or this (5 of 5 users have voted)

    users | votes | passed
      5       5        1

     

    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

  3. 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");
    ?>
  4. <?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?

  5. If you only want the row count, then it's extremely inefficient to load the entire table into PHP. Let MySQL do the counting:

    <?php
    
    $userCount = $db_con->query('SELECT COUNT(*) FROM users WHERE enabled')->fetchColumn();
    
    $voteCountStmt = $db_con->prepare('SELECT COUNT(*) FROM votes WHERE motions_id = :motionid');
    $voteCountStmt->execute(['motionid' => $motionid]);
    $voteCount = $voteCountStmt->fetchColumn();
    

    If you want both the count and the actual data, then use fetchAll() in both cases. When you use fetch(), you only get a single row, regardless of how big the result set actually is.

     

    Thanks Jacques1!  then I could do the conditional if $voteCount == $usercount ?

  6. you probably have a type conversion problem or a null value that's matching all values.

     

    a) how do you know the second query is (apparently) matching 5 rows? you have only shown the code getting the result from the queries. perhaps there's a logic error or a mis-display of the results?

     

    b) what exactly does using var_dump($motionid); show and what ARE the motions_id values in the incorrect result set?

     

    c) how did the rows of data get inserted into the votes table and what is the column definition for the motions_id column?

    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.

     

    You're using fetch() for the second query, which returns a single row. When you apply count() to that row, you're counting columns, not rows.

     

    What's the point of that counting stuff anyway? You expect one row, you fetch one row, yet for some reason you check for more than one row. What's the real problem here?

    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.

  7. 
    
    $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?

  8. Another way to separate the PHP code from the SQL query is to use clear formatting:

    $addDiscussion = $db_con->prepare('
        INSERT INTO
            discussion (user_id, motion_id, discussion_text)
        VALUES
            (:userid, :motionid, :text)
    ');
    

    But really the most important step is configure the error handling. No database API just silently refuses to execute a query, there's always a detailed error message available. PHP usually expects you to fetch it manually (which is unrealistic), but when you enable exceptions, you'll get it automatically.

    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.

     

    You really should have error reporting turned on and an IDE that will flag syntax errors (it'll make life much easier). I would also separate the query from the prepare.

     

    Here's an example of mine ->

    $query = 'INSERT INTO trivia_questions (question, answer1, answer2, answer3, answer4, correct, category, play_date) VALUES (:question, :answer1, :answer2, :answer3, :answer4, :correct, :category, NOW())';
    
    $stmt = $pdo->prepare($query);
    

    That way you can easily debug the script. Everyone who writes code gets syntax errors which are easily fixable and the less time you spend on them the more you can concentrate on the baddies (logic errors).  :  :happy-04:

    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.

     

    Once again: Read the previous posts before you reply.

     

    It's great that you want to help, but it's not helpful to post false information which contradicts the facts that have already been established. No, the code is not OK. As I've already said, the query is syntactically wrong. Looking somewhere else isn't going to fix that.

    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.

  9. Can you be a bit more specific? We can neither see your screen nor read your mind.

     

    What exactly happens? An error? A blank page? Something else? If it's a blank page, enable PDO exceptions, turn your error reporting all the way up and make PHP display the messages on the screen (assuming this is your development machine, not the live server).

    The echo runs but the INSERT does not actually run. I have my my sql server running everything and the INSERT is not executing. 

  10. 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";
                                    }
                            ?>
    
    
  11. 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? 

  12. 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. 
  13. technically, there's nothing that would prevent your code from working. however, i can name at least a half-dozen things that could make it 'appear' like it isn't working.

     

    do you have php's error_reporting set to E_ALL and display_errors set to ON, so that php would help you by reporting and displaying all the errors it detects. i'm betting you would be getting php errors that would help pin down the problem.

     

    next, what is the user_id value supposed to be? one of the possibilities for why it may not be 'appearing' is if it happened to intentionally or accidentally be in the form of a html tag, in which case it would appear in the 'view source' of the page and not be displayed.

     

    lastly, you need an exit; statement after the header() redirect to stop program execution. the current code allows a non-logged in user to access the page since all the code still runs.

     

    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.

  14. <?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

  15. I am creating a PHP application that the HOA board will use to do some online voting between the board. That being said I would like to have an async job run every 24 hours at 6:00p.m. that would see what motions users have not voted on and e-mail them to let them know they need to vote on it.

     

    Any suggestions would be greatly appreicated

  16. I am attempting to get this demo to work in FF. The author has stated his code only works in Chrome. I have added the necessary -moz- calls for the CSS3 vendor specific calls. It still does not work in FF. The text is not supposed to be load all at once. It is supposed to load a little at a time.

     

    CSS

    @font-face {
    font-family: 'Qlassik';
    src: url('http://bmcenterprises.wdfiles.com/local--files/fonts/Qlassik_TB-webfont.eot');
    src: local('?'), url('http://bmcenterprises.wdfiles.com/local--files/fonts/Qlassik_TB-webfont.woff') format('woff'), url('http://bmcenterprises.wdfiles.com/local--files/fonts/Qlassik_TB-webfont.ttf') format('truetype'), url('http://bmcenterprises.wdfiles.com/local--files/fonts/Qlassik_TB-webfont.svg#webfont') format('svg');
    font-weight: normal;
    font-style: normal;
    }
    
    
    html {
    height: 100%;
    width: 100%;
    }
    html {
    background-color: #fff;
    background-image: linear-gradient(top, #fff, #e4e4e4);
    }
    
    
    
    #content {
    display: block;
    position: absolute;
    top: 50%;
    width: 98%;
    padding: 0;
    margin-top: -200px;
    text-align: center;
    height: 400px;
    }
    
    
    .fade-in {
    font: normal 40px/2 'Qlassik';
    color: #333;
    }
    
    
    .one {font-size: 50px;}
    .five {font-size: 30px;}
    
    
    @-moz-keyframes reset {
    0% {
    opacity: 0;
    }
    100% {
    opacity: 0;
    }
    }
    
    
    @keyframes reset {
    0% {
    opacity: 0;
    }
    100% {
    opacity: 0;
    }
    }
    
    
    @-moz-keyframes fade-in {
    0% {
    opacity: 0;
    }
    60% {
    opacity: 0;
    }
    100% {
    opacity: 1;
    }
    }
    
    
    @keyframes fade-in {
    0% {
    opacity: 0;
    }
    60% {
    opacity: 0;
    }
    100% {
    opacity: 1;
    }
    }
    
    
    .fade-in {
    -moz-animation-name: reset, fade-in;
    -moz-animation-duration: 3s;
    -moz-animation-timing-function: ease-in;
    -moz-animation-iteration-count: 1;
    animation-name: reset, fade-in;
    animation-duration: 3s;
    animation-timing-function: ease-in;
    animation-iteration-count: 1;
    }
    
    
    .fade-in.one {
    -moz-animation-delay: 0, 0;
    animation-delay: 0, 0;
    }
    
    
    .fade-in.two {
    -moz-animation-delay: 0, 1s;
    animation-delay: 0, 1s;
    }
    
    
    .fade-in.three {
    -moz-animation-delay: 0, 1.5s;
    animation-delay: 0, 1s;
    }
    
    
    .fade-in.four {
    -moz-animation-delay: 0, 2s;
    animation-delay: 0, 2s;
    }
    
    
    .fade-in.five {
    -moz-animation-delay: 0, 3s;
    animation-delay: 0, 3s;}
    
    
    a.again {
    background-color: #6bd3ee;
    background-image: linear-gradient(top, #6bd3ee, #2c9bd4);
    font-size: 20px;
    font-weight: normal;
    padding: 5px 18px;
    border-radius: 20px;
    border-top: 1px solid #baebfc;
    box-shadow: 1px 1px 0 #1c92b0, 0 2px 2px rgba(0,0,0,0.4);
    color: #fff;
    text-shadow: #257ca7 0 1px 1px;
    background-clip: padding-box;
    -webkit-background-clip: padding-box;
    text-decoration: none;
    font-family: 'Qlassik';
    margin: 40px 10px 0;
    display: inline-block;
    -moz-animation-name: reset, fade-in;
    -moz-animation-duration: 6s;
    -moz-animation-timing-function: ease-in;
    -moz-animation-iteration-count: 1;
    -moz-animation-delay:0, 6s;
    animation-name: reset, fade-in;
    animation-duration: 6s;
    animation-timing-function: ease-in;
    animation-iteration-count: 1;
    animation-delay:0, 6s;
    }
    a.again:hover {
    background-color: #6ad9fa;
    background-image: linear-gradient(top, #6ad9fa), #39b0ed);
    color: #fff;
    text-decoration: none;
    }
    a.again:active {
    background-color: #22b4d9;
    background-image: none;
    }
    a.again.red {
    background-color: #b02b34;
    background-image: linear-gradient(top, #ee3c42), #b02b34);
    border-top: 1px solid #f1554a;
    box-shadow: 1px 1px 0 #bc2f38, 0 2px 2px rgba(0,0,0,0.4);
    text-shadow: #98262d 0 1px 1px;
    }
    a.again.red:hover {
    background-color: #ff434f;
    background-image: linear-gradient(top, #ff434f), #cb333a);
    }
    a.again.red:active {
    background-color: #ba313a;
    background-image: none;
    }
    a.again:before {
    content: '\2190 ';
    font-weight: bold;
    }
    a.again.red:before {
    content: '';
    }
    

     

     

    HTML

    <div id="content">
    
    <p>
    <span class="fade-in one">Tomorrow will be just another day.</span>
    </p>
    
    <p>
    <span class="fade-in two">That you will</span> <span class="fade-in three"> never</span> <span class="fade-in four"> forget.</span>
    </p>
    
    <p>
    <span class="fade-in five">See you at 10am.</span>
    </p>
    
    <p>
    <a href="/blog:animated-page-entry-with-css3" class="again">back to the BMC Blog</a> <a href="/local--code/blog:animated-page-entry-with-css3/5" class="again red">see it again</a>
    </p>
    
    </div>
    

  17. How can you specify the salt but allow for all combinations? What I want to do is to utilize crypt to hash my passwords with a salt but as I am well aware each time it generates the hash, the salt is difference so the stored hash is different. If there a way to determine what the salt is? Either way when I know what the salt is, I will have to store it in my database table as the salt for each user will be different.

     

    Thanks

     

    M. Brown

×
×
  • 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.