will35010 Posted June 2, 2009 Share Posted June 2, 2009 I cannot get this script to echo anything out. <?php //Database Settings $dbhost = "localhost"; $dbuser = "*****"; $dbpass = "*****"; $dbname = "vehicles"; $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Error connecting to mysql'); $sql = "SELECT fname, lname, dl FROM drivers"; $rs = mysql_query($sql, $conn); while($row = mysql_fetch_array($rs)) { echo "<option value=\"" . $row['dl'] . "\">".$row['lname'].",".$row['fname']."</option>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160686-solved-mysqlphp-query-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 2, 2009 Share Posted June 2, 2009 You are mixing mysql and mysqli functions. You need to pick one or the other. They cannot be mixed for a single connection to a database server. You should also be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini so that you will get immediate feedback from problems that php can detect. Quote Link to comment https://forums.phpfreaks.com/topic/160686-solved-mysqlphp-query-problem/#findComment-848008 Share on other sites More sharing options...
Alex Posted June 2, 2009 Share Posted June 2, 2009 $rs = mysql_query($sql); The connection isn't a parameter of mysql_query() Edit: And yea, you have to change it to a mysql connect, not mysqlite. Quote Link to comment https://forums.phpfreaks.com/topic/160686-solved-mysqlphp-query-problem/#findComment-848009 Share on other sites More sharing options...
will35010 Posted June 2, 2009 Author Share Posted June 2, 2009 Thanks for catching the mysqli problem! I had error reporting on and it still doesn't show any errors or echo anything out to even the html source. My query is good and returns data when run CLI. New Script: <?php error_reporting(E_ALL); //Database Settings $dbhost = "localhost"; $dbuser = "******"; $dbpass = "*****"; $dbname = "vehicles"; $conn = mysql_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Error connecting to mysql'); $sql = "SELECT fname, lname, dl FROM drivers"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"" . $row['dl'] . "\">".$row['lname'].",".$row['fname']."</option>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160686-solved-mysqlphp-query-problem/#findComment-848013 Share on other sites More sharing options...
will35010 Posted June 2, 2009 Author Share Posted June 2, 2009 $rs = mysql_query($sql); The connection isn't a parameter of mysql_query() Edit: And yea, you have to change it to a mysql connect, not mysqlite. You can include the link: http://us.php.net/function.mysql-query Quote Link to comment https://forums.phpfreaks.com/topic/160686-solved-mysqlphp-query-problem/#findComment-848017 Share on other sites More sharing options...
PFMaBiSmAd Posted June 2, 2009 Share Posted June 2, 2009 error_reporting set to E_ALL and display_errors set to ON Unless you have both settings in a known state, you won't see any errors displayed. Quote Link to comment https://forums.phpfreaks.com/topic/160686-solved-mysqlphp-query-problem/#findComment-848018 Share on other sites More sharing options...
will35010 Posted June 2, 2009 Author Share Posted June 2, 2009 It gave me this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/test/vehicle/test.php on line 19 That's this: while($row = mysql_fetch_array($rs)) Quote Link to comment https://forums.phpfreaks.com/topic/160686-solved-mysqlphp-query-problem/#findComment-848029 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.