0

I'm trying to write this function of this program that will extract a value (one that they click on from a list of values) from a mySQL table. When I write this code, It always gives me the error "No database Selected."

I am trying to extract values from a table (performed_in) inside of the schema movies. The user selects a name, then the program is supposed to search the table "performed_in" and return values (all of the fields) that match what the user selected.

Even if my type something like this, it doesnt connect.

mysql_connect('localhost', 'uMoviesUser', '');

The problem seems to be inside of the query line. What is wrong with it?

 $moviesdb = new mysqli('localhost', 'uMoviesUser', '', 'movies');
 if (mysqli_connect_errno()) {
 echo '<h3>Database Access Error!</h3>';
 }
 else {
 $select = "select * from performed_in";
 $select .= " where name = '".$_GET['name']."'";
 $res = mysql_query($select) or die(mysql_error());

 while($row = mysql_fetch_array($res)){
 echo $row;
 }
Kyle
  • 55
  • 1
  • 4
  • 2
    You are mixing mysqli and mysql functions! These are two entirely separate database interfaces. Stick to one or the other. If you still have problems with code that *should* work, please try again and tell us the exact problem and error messages. – deceze Apr 24 '12 at 05:56
  • This actually fixed it. I was using new mysqli('etc', 'etc', 'etc'), but when I brought it to mysqli('etc','etc','etc') it worked. – Kyle Apr 24 '12 at 06:45

2 Answers2

0

Besides the above comment u havn't used a the function to select the database which is mysql_select_db

  $db_selected = mysql_select_db('urDB', $connection);
    if (!$db_selected) {
       die ('Can\'t use urDB: ' . mysql_error());
    }
altsyset
  • 339
  • 2
  • 20
0

I was using new mysqli('etc', 'etc', 'etc'), but when I brought it to mysqli('etc','etc','etc') it worked.

The others solutions weren't really any closer then my original one.

Kyle
  • 55
  • 1
  • 4