Hey, I'm trying to program a group-request system and now I'm struggling a little bit with the code. Well, I'll try my best to explain what I'm trying to do.

requests.png

I want, that when I click the accept button, ONLY the name from the person next to the accept button is getting inserted into the SQL Database. Here is my code:

    <?php
    $servername = "localhost";
$dbname = "psychopath";
$username = "root";
$password = "";

try{
    $dsn = "mysql:host=" . $servername . ";dbname=" . $dbname;
    $db = new PDO($dsn, $username, $password);
    echo "";
}catch(PDOException $e){
    echo $e.getMessage();
}
    $name = $_GET['name'];
        $show_request =$db->prepare("SELECT * FROM group_requests WHERE view_status = 'unseen' AND accepted = 'no'");
        $show_request->execute();



        while($row=$show_request->fetch()){


              $sender = $row['request_sender'];
             echo "<b>$sender</b><form method='get'><input type='submit' name='accept' id='accept' value='accept'/><a></a></form><br>";


               }
               ?>

I think, if I can get the $sender variable out of the while loop, than it should work, or? How you can see, I'm not sure how I can fix the problem. Hope, you guys can help :)

I'm sorry, I'm still very confused what you're trying to do.

I see on line 14 of the code above, you have $_GET['name']. That means that the page is meant to be loaded as file.php?name=Foo with a query string like that. If you're talking about clicking the Submit button on a form, I suspect submitting the form as a POST request and so you're looking for $_POST['name'] instead.

Then I see you have the SQL query to select all rows from the group_requests table that are useen and not accepted. I'm not seeing anything that uses this variable $name.

Then I'm seeing you are looping through the results, and for each request sender, you have a button that does, much to my surprise, do a GET request when submitting the form, not a POST request. So clicking the accept button should redirect you to file.php?accept=accept.

What do you mean by getting the sender variable out of the while loop?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.