Handling select box (drop-down list) in a PHP form

Hey there,

I need help with select box (drop-down list) in a PHP form, i had tried many times but not working and also my php code is contact with mysql.

Here is my code.

[php]<?php

$result = mysqli_query($con,“SELECT * FROM image_gallery”);

while($row = mysqli_fetch_array($result)){

	$title = $row['title'];
	$discription = $row['discription'];
	$cid = $row['cid'];

	echo "<a href =\"edit.php?cid=$cid\">$title</a><br>";

} [/php]

thank you

Well, you are pulling an array from the query. This means you need to use indexes like [1] or [5] to
point at fields and you must know the exact order your fields were created in.

But, in your anchor code inside the WHILE, you are using the associated values with those fields.

The easiest way is to just pull the associated array instead. Change your while to this:
[php]
while($row = mysqli_fetch_assoc($result)){
[/php]
This will pull the associated text values so you can use them with the $row[‘field-name’] as you have
in your code.

Hope that makes sense. There are a lot of tutorials out on the web, but, I think you might enjoy this
site as it explains these items simply. Just select the item you want to to read about on the left. Lots of
great info on this site. It might help with your project…
http://www.w3schools.com/php/func_mysqli_fetch_assoc.asp

Readers know I’m getting better and now I am fine. Makes me want to study this further.

Aziz, not sure what Doll was talking about, but, did this fix get your code to work correctly?

If so, let us know so we can mark this solved… Let us know…

Sponsor our Newsletter | Privacy Policy | Terms of Service