Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP dropdown menu populating from mysql not working

I've spent hours reading and trying to figure out why this is not working but the drop down menu does not populate. I think it's something simple but I just cannot see it. Anyone?

dbconn.php

<?php

define('DB_NAME' , 'artprints');
define('DB_USER' , 'root');
define('DB_PASS' , '');
define('DB_HOST' , 'localhost');

func.php

<?php

include_once 'dbconn.php';

function connect(){
    $connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS) or die ('Could not connect to the database' . mysl_error());
    mysqli_select_db($connection, DB_NAME);
}

function close(){
    mysql_close();
}

function query(){
    $myData = mysql_query("SELECT * FROM artists");
    while ($record = mysql_fetch_array($myData)){
    echo '<option value="' . $record['artistID'] . '">' . $record['artistID'] . '</option>';
    }
}

test.php

<?php
 include_once 'func.php';
 connect();
 ?>

 <html>
 <head>
 <title>Drop down testing</title>
 </head>
 <body>
 <select name='artist'>
 <?php query() ?>
 </select>
 <?php close() ?>
 </body>
 </html>
like image 934
oldmanpete Avatar asked Mar 20 '26 02:03

oldmanpete


1 Answers

You are mixing mysqli_* and mysql_*

mysqli_connect and mysqli_select_db

against

mysql_query and mysql_fetch_array

like image 93
davidkonrad Avatar answered Mar 22 '26 10:03

davidkonrad