0

In my dropdown list, i put all the "pack_name(s)" the user has posted and I display it all in the list for the user to select and update. So when the user selects one and hits submit, i want to get that "value" submitted and use it for later purposes but ive been researching and only found "pre-set" values with html and the value was given using Jquery. So i wondering if its possible to basically take the "pack_name" selected and when the user hits submit, echo out the selected value.

PHP

<?php
session_start();

 if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error...
        $postMax = ini_get('post_max_size'); //grab the size limits...
        echo "<p style=\"color: #F00;\">\nPlease note files larger than {$postMax} will result in this error!</p>"; // echo out error and solutions...
        return $postMax;
    }

if(isset($_COOKIE['id'])){

    if($_SESSION['came_from_upload'] != true){

        setcookie("id", "", time() - 60*60);
        $_COOKIE['id'] = "";
        header("Location: developerLogin.php");
        exit;


    }

    try{

        // new php data object 
        $handler = new PDO('mysql:host=127.0.0.1;dbname=magicserver', 'root', '');
        //ATTR_ERRMODE set to exception
        $handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        }catch(PDOException $e){
             die("There was an error connecting to the database");   

        }
       $userid = $_SESSION['id'];
       $stmt = $handler->prepare("SELECT * FROM pack_profile WHERE pack_developer_id = :userid");
       $stmt->bindParam(':userid', $userid, PDO::PARAM_INT);
       $stmt->execute();
       echo "<select>";

       while($result = $stmt->fetch()){
         echo "<option>" . $result['pack_name'] ."</option>";
       }

       echo "</select>";

   if($_SERVER['REQUEST_METHOD'] =="POST"){
         $token = $_SESSION['token'];


}
}


?>
2
  • So what's part of the code isn't working? Please be more specific. Are you getting any errors? Commented Aug 8, 2017 at 1:44
  • no errors, i am trying to echo the result that was selected. I am very specific in my explanation. Commented Aug 8, 2017 at 1:45

1 Answer 1

1

You need to give the select element a name attribute, and give each option element a value attribute.

For example:

   echo "<select name=\"pack\">";

   while($result = $stmt->fetch()){
     echo "<option value=\"" . $result['pack_name'] . "\">" . $result['pack_name'] ."</option>";
   }

   echo "</select>";

Of course you should be escaping anything which could contain &, < or " with something like htmlspecialchars().

Sign up to request clarification or add additional context in comments.

6 Comments

Oh so now do i just echo the "result"
Result will be in $_POST['pack'] or $_GET['pack']. Your question is confusing since you already have advanced concepts like sessions, file uploads and indeed even $_POST in your code yet you don't seem to know basics how forms work. I'm assuming you are outputting a form element eg <form action="something" method="POST"> somewhere? It's not in your code.
I am so sorry i had a bad headache yesterday but i tried "echo $_POST['pack'}" and i got an error saying "( ! ) Notice: Undefined index: pack in C:\wamp64\www\MT\developer_packupdater.php on line 48 "
I think maybe it would be wise to employ someone who knows web development or PHP to do this work for you - I just feel that it's going to take a bit too much to lead you through this.
Well i am doing this just to learn but thanks for the suggestion.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.