Trying to create a form in php the link doesn't seem to work

Hello all.
I have connected a databse, all is ok but i’d like to link the drop down option so when the user selects his/her name it will go to a page with their info on it. Preferably on the same page. but for now i have it on a separate one.
The db is providing the info but the link doesn’t seem to work

Not done this one before hope i can get some advice.
Thank you
D

<div id="content" class="content">
		<div id="select1" class="select1"> 

		<?php 
		if($msg){
		echo "<h3>$msg</h3>";
		}else{ ?>
		
		<select class="section">
		<?php
		while($row = $result->fetch_assoc()) { ?>

				<option value="<?php echo $row['firstname']; ?>">
				<a href="details.php?id=<?php echo $row['id']; ?>">
				<p><?php echo $row['firstname']; ?></p>
				<p><?php echo $row['lastname']; ?>  </p></br>
				<div class="description"><?php echo $row['email']; ?></div>
				</a>
				</option>

		<?php 	} //end loop ?> 
		</select>
		
		<?php } ?>

			
			

		</div> <!-- end select1  -->
		
		<div id="select2" class="select2"> 
		
		
		</div> <!-- end select2  -->
	</div> <!-- end content-->

In what way? When you click the link does it go anywhere? Is the link correct when you view the relevant section in html?

hi, it goes nowhere and doesn’t even recognize it is a link. pointer doesn’t’ turn into a hand either.
D

As I say the first thing I would do is “view source” to see what html has been generated.

Is this supposed to be a dropdown list?

Well you can’t put links, <p> tags etc inside select options. The select should be in a form tag and the select should have a name attribute. This sample has the form action attribute pointing to the same page and I assigned the id as the option value. I’m sure you have other code on your page, but at the TOP before output to the browser you can check for the POST and use a header to direct user to the details page. This is just a sample based on what you have.

<?php
if(!empty($_POST['section'])):
    header("location: details.php?id=".$_POST['section']); 
    exit;
endif;
?>
<html>
<body>
<div id="content" class="content">
        <div id="select1" class="select1"> 

        <?php 
        if(!empty($msg)){
            echo "<h3>$msg</h3>";
        }else{ ?>
        <form action="" method="post">
        <select class="section" name="section" onchange="this.form.submit()">
        <option value="">-</option>
        <?php
        while($row = $result->fetch_assoc()) { 
        ?>

                <option value="<?php echo $row['id']; ?>"><?php echo $row['firstname']; ?> <?php echo $row['lastname']; ?>  <?php echo $row['email']; ?></option>

        <?php     
        } //end loop 
        ?> 
        </select>
        </form>
        <?php } ?>

            
            

        </div> <!-- end select1  -->
        
        <div id="select2" class="select2"> 
        
        
        </div> <!-- end select2  -->
    </div> <!-- end content-->       
    
</body>
</html>

Thank you Rubble & Drummin will try out the suggestions. see if i can put it up on my live server over the weekend and get it to work.
And yes rubble it was a dropdown list.
D

Just checking as your

@Drimmin your answer is absolutely right we also solve the same issue at 1 month ago. good job :smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.