Discuss Populate from MySQL...stuck in the PHP Development forum on Dev Shed. Populate from MySQL...stuck PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Time spent in forums: 2 Months 3 Weeks 6 Days 17 h 28 m 11 sec
Reputation Power: 1092
an associative array isn't an object, so you cannot use the "->" syntax on it. Actually, your screen should be flooded with error messages, but I guess your PHP is misconfigured. Turn on all error messages in your php.ini:
error_reporting = -1;
display errors = On;
Or do it in the code itself.
Also the old MySQL extension is ancient, it's obsolete since almost a decade and will be officially deprecated in the next PHP version. If you got any chance to switch to one of the "new" extensions, do it.
Time spent in forums: 5 Days 20 h 8 m 58 sec
Reputation Power: 7
This would be similar to something I may do in your situation. I usually have such drop-downs built a few times in my projects, so I create it as a function. This has been edited to fit your single item, as well as updated to use mysqli instead of the deprecated mysql.
Time spent in forums: 4 h 31 m 56 sec
Reputation Power: 0
Sorry, just very frustrated with this. I realize it simple and yet I just can't figure it out. I appreciate all help given.
Here is the code with your suggestion. I get the dropdown box with Please Select and message Connected successfully but that is it. So I know that connection to db works but where I am going wrong with populating dropdown box I am at a loss. I have been at it for days and Googled it to bits...Charpters here I come I guess...lol
The table has one row with id1 and 50 columns. Each column has a value:
Column1 = Value1
Column2 = Value2
and so on
This all code I have. There is nothing else.
$host="localhost"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="test_db"; // Database name
$tbl_name="test_table"; // Table name
//Connect to server and select database.
$conn = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");