SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Update SQL Record through PHP Form Not working

    Im Trying to build a Website that allows people to look for announcements and earn points for actions. However, I cant adjust these points through the form I built. Can anyone Please help?

    PHP Code:
    <?php 
        ob_start
    ();

        require(
    'extra/header.php');

        if(empty(
    $_GET['id'])) 
        { 
            
    header("Location: index.php"); 
            exit;
        } 
        if(
    $_SESSION['adminlevel'] == 0
        { 
            
    header("Location: dashboard.php"); 
            exit;
        } 
        if(empty(
    $_GET['id'])) 
        { 
            
    header("Location: index.php"); 
            exit;
        } 
        
    $userid $_GET['id'];
        
    $userid intval($userid);

        if(!
    is_numeric($userid))
        {
            
    header("Location: index.php");
            exit;
        }  

        if(isset(
    $_POST['Submit'])){//if the submit button is clicked
        
        
        
    $points $_POST['points'];
        }

        
    $submitted_username ''
         
            
    $query 
               SELECT 
                    username, 
                    email,
                    verified,
                    admin,
                    vtcstaff,
                    streamer,
                    mediateam,
                    suspended,
                    regdate
                    FROM users 
               WHERE 
                    id = :id 
            "

            
    $query_params = array( 
                
    ':id' => $userid
            
    ); 
            
        
    $query1 
                    INSERT INTO users ( 
                        points
                    ) VALUES ( 
                        :points
                    ) 
                    WHERE 
                    id = :id 
                "

                 

                
    $query_params1 = array( 
                    
    ':id' => $userid
                    
    ':points' => $_POST['points'],

                ); 
             
            try 
            { 
                
    $stmt $db->prepare($query); 
                
    $result $stmt->execute($query_params); 
            } 
            catch(
    PDOException $ex
            {
                die(
    "Failed to run query: " $ex->getMessage()); 
            } 
            
            
    $row $stmt->fetch(); 
            if(
    $row['verified'] == && $row['suspended'] == 0)
            {
                
    $verified "<span class=\"label label-warning\">Not Verified</span>";
            }
            else if(
    $row['verified'] == && $row['suspended'] == 1)
            {
                
    $verified "<span class=\"label label-danger\">Suspended User</span>";
            }
            else if(
    $row['verified'] == && $row['suspended'] == 0)
            {
                
    $verified "<span class=\"label label-success\">Verified User</span>";
            }
            else if(
    $row['verified'] == && $row['suspended'] == 1)
            {
                
    $verified "<span class=\"label label-danger\">Suspended User</span>";
            }
            if(
    $row['vtcstaff'] == 1)
            {
                
    $vtcstaff "<span class=\"label label-success\">VTC Staff</span>";
            }
            if(
    $row['streamer'] == 1)
            {
                
    $streamer "<span class=\"label label-success\">Official Twitch Streamer</span>";
            }
            if(
    $row['mediateam'] == 1)
            {
                
    $media "<span class=\"label label-success\">Media Team</span>";
            }
            if(
    $row
            { 
                
    $regdate htmlentities($row['regdate'], ENT_QUOTES'UTF-8');
                
    $regdate strtotime($regdate);
                
    ?>

                    <div class="container">
                        <center>
                            <h3>User Information</h3>
                            <div class="well well-sm" style="width: 500px;"><a href="verify.php?id=<?php echo $_GET['id']; ?>">VERIFY</a> - <a href="suspend.php?id=<?php echo $_GET['id']; ?>">SUSPEND</a> - <a href="media.php?id=<?php echo $_GET['id']; ?>">Add to Media Team</a></div>
                            <div class="well well-sm" style="width: 500px;"><b>Username: </b> <?php echo stripslashes(htmlentities($row['username'], ENT_QUOTES'UTF-8')); ?></div>
                            <div class="well well-sm" style="width: 500px;"><b>Status: </b> <?php echo $verified; echo $vtcstaff?><?php echo $streamer; echo $media ?></div>
                            <div class="well well-sm" style="width: 500px;"><b>Registration Date: </b> <?php echo date("m-d-Y"$regdate); ?> </div>
                            <br />
                            <?php
                            
                            $query 

                                SELECT 
                                    *                
                                    FROM drive_routes
                                    WHERE status = 2 AND driver = "
    $_GET['id'] ."
                            "


                            try 
                            { 
                                
    $stmt $db->prepare($query); 
                                
    $result $stmt->execute(); 
                            } 
                            catch(
    PDOException $ex
                            { 
                                die(
    "Failed to run query: " $ex->getMessage()); 
                            } 
                                      
                            
    $countroutes $stmt->rowCount();
                            
                            
    $query1 
                                SELECT 
                                    *                
                                    FROM drive_routes
                                    WHERE status = 2 AND driver = "
    $_GET['id'] ."
                            "


                            try 
                            { 
                                
    $stmt2 $db->prepare($query1); 
                                
    $result $stmt2->execute(); 
                            } 
                            catch(
    PDOException $ex
                            { 
                                die(
    "Failed to run query: " $ex->getMessage()); 
                            } 

                            
    $rows2 $stmt2->fetchAll();
                            
    $totalmoney 0;
                            
    $total 0;

                            foreach(
    $rows2 as $row){
                            
                                
    $total $total $row['distance'];
                            
                                
    $totalmoney $totalmoney + ($row['price'] - $row['costs']);
                                            
                            }
                            
    ?>
                            
                            <h3>Driving Information</h3>
                            <div class="well well-sm" style="width: 500px;">
                                <b>Total Accepted Deliveries: </b> <?php echo $countroutes?></br>
                                <b>Total Miles Driven: </b> <?php echo $total?></br>
                                <b>Total Money Earned: </b> <?php echo $totalmoney?></br>                        
                            </div>
                            
                            <h3> Add Points
                            <div class="well well-sm" style="width: 500px;">
                                    <form class="form-signin" role="form" action="editprofile.php" method="post">
                                    <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
                                    <input type="number" name="points" class="form-control" placeholder="points" required><br />
                                    <button class="btn btn-lg btn-primary btn-block" type="submit">Confirm</button>
                                    </form>
                            </div>
                        </center>
                    </div>
                <?php require('extra/footer.php'); ?>
                
                <?php
            

            else
            {
                    echo
    "<div class= \"container \">";
                    echo
    "        <br />";
                    echo
    "        <h2>Error!</h2>";
                    echo
    "        <p>This profile doesn't exist, try another!</p>";
                    echo
    "</div>";
                    require(
    'extra/footer.php');
            }
        
    ?>
    Thanks For Any Help!

  2. #2
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    772
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    A quick look... the only thing I spotted was a comma after last value of this array. $_POST['points'], Remove.
    PHP Code:
     $query_params1 = array( 
                    
    ':id' => $userid
                    
    ':points' => $_POST['points'],

                ); 
    EDIT.... Hmmm
    Does look like you are executing that query after all.
    PHP Code:
        $query1 
                    INSERT INTO users ( 
                        points
                    ) VALUES ( 
                        :points
                    ) 
                    WHERE 
                    id = :id 
                "

                 

                
    $query_params1 = array( 
                    
    ':id' => $userid
                    
    ':points' => $_POST['points'],

                ); 

  3. #3
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know why I get this Notice?
    Code:
    Notice: Undefined index: points in C:\xampp\htdocs\ALPHA\editprofile.php on line 70

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Does
    $_POST['points']
    have a value?

  5. #5
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Page where this is on is a page that allows admins to alter the amount the points that users currently have. They have a default Point score of 0.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •