-1

Trying to access a DB and display the contents of imageurl located in movie table dose not seem to work. any suggestions?

<?php
//connect to DB
$db = mysqli_connect("localhost", "awalke32", "21195453", "awalke32");
if (mysqli_connect_errno($db)) {
    print "Connect failed: " . mysqli_connect_error();
    exit();
} else {
    $myint = rand("1", "37"); //random number gererator

    $query = ("SELECT imageurl FROM movie WHERE movie_id=" . $myint); //think the error is in here but it works in Terminal secure shell
    $result = mysql_query($query);

    print "<table width=\"100%\"><tr>";
    print "<td align=\"center\">";
    print "<img src='images/" . $result . "' alt='Image'>"; //this is correct as it works in another page
    print "</td>";
    print "</td></tr></table>";
}
?>
Alexander Yancharuk
  • 13,817
  • 5
  • 55
  • 55
user1908962
  • 533
  • 1
  • 6
  • 10

2 Answers2

1

Change the line: $myint = rand ("1", "37"); to $myint = rand (1, 37);

Oras
  • 1,036
  • 1
  • 12
  • 18
  • Thanks think these work now getting an error message. "Could not run queryAccess denied for user 'apache'@'localhost' (using password: NO)" – user1908962 Sep 08 '13 at 03:01
0

Argument send as int in rand function

and

Fetch data array from result

$myint = rand (1, 37);

$query = ("SELECT imageurl FROM movie WHERE movie_id=".$myint);

$result = mysql_query($query);

if($row = msyql_fetch_array($result)) {
    $image = $row["imageurl"];

    print "<table width=\"100%\"><tr>";
    print "<td align=\"center\">";
    print "<img src='images/".$image."' alt='Image'>";
    //this is correct as it works in another page
    print "</td>";
    print "</td></tr></table>";
}
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89