Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hello,

 

I am trying, without success I might add, to execute a simple query.  One variable is passed as a $_GET value which is movie_id.  I defined a variable $movie_id = $_GET['movie_id'];

 

I then wrote a query: SELECT * FROM movies WHERE movie_id = $movie_id

 

I'll paste the relevant script below. 

 

require_once ('../mysqli_connect.php');
$movie_id = $_GET['movie_id'];
$q = mysqli_query("SELECT * FROM movies WHERE movie_id = '$movie_id'");
$r = mysqli_fetch_array ($dbc, $q);


echo '
<table cols="2" width="1100px" align="center">
<tr>
<td align="left" width="240px"><img src="img/boxcovers/small/movie_' . $r['movie_id'] .'_small.jpg"></td>
<td></td>
</tr>
<tr>
<td align="center" width="960px">

 

Can anyone help?
 

Link to comment
Share on other sites

Still getting errors.  Here I am right now (I'll only include the relevant part and then the error

 

require_once ('../mysqli_connect.php');
$movie_id = $_GET['movie_id'];
$q = "SELECT * FROM movies WHERE movie_id = $movie_id";
$r = mysqli_fetch_array ($dbc, $q);


echo
'<table cols="2" width="1100px" align="center">
<tr>
<td align="left" width="240px"><img src="img/boxcovers/small/movie_' . $r['movie_id'] .'_small.jpg"></td>
<td></td>
</tr>
<tr>
<td align="center" width="960px">
 

 

ERROR IS:

 

PHP Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in /Applications/MAMP/htdocs/movie2.php on line 30  (Line 30 is $r)
 

Link to comment
Share on other sites

It's because you haven't actually executed the query yet with mysqli_query. Use that function to execute the query and store the result in a variable. From there, make the first argument of mysqli_fetch_array the returned results object, not the DB connection.

Link to comment
Share on other sites

I'm still doing it wrong, am I using the mysqli_query function incorrectly?

 

Tried this:

 

require_once ('../mysqli_connect.php');
$movie_id = $_GET['movie_id'];
$q = mysqli_query("SELECT * FROM movies WHERE movie_id = $movie_id");
$r = mysqli_query($q, $dbc);
 

 

Got this:

 

PHP Warning:  mysqli_query() expects at least 2 parameters, 1 given in /Applications/MAMP/htdocs/movie2.php on line 29

 

PHP Warning:  mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/MAMP/htdocs/movie2.php on line 30
 

Link to comment
Share on other sites

 Share

×
×
  • Create New...