-2

This morning this scipt was working perfectly, but now I am getting an error on line 7 that id is undefined:-

<?php
     $m = new mysqli("localhost","scott","tiger","movie");
     if($m->connect_errno){
         die("Database connection failed");
     }
     $m->set_charset('utf8');
     $id = $_REQUEST["id"];
     $sql = "
     SELECT name,title, movieid
        from casting 
        join actor on (actorid = actor.id)
        join movie on (movieid = movie.id)
        where actorid=$id";

     $res = $m->query($sql);
     while($row = $res->fetch_assoc()){
         echo "<p>$row[name] - <a href=movies3.php?id=$row[movieid]>$row[title]</a> </p>";
}
12
  • Can you share html code ?? Mar 9, 2016 at 1:34
  • this code seems ok to me (on line 7) ... but look at the code that posts the request
    – ratmalwer
    Mar 9, 2016 at 1:35
  • this is is all code and it used to read data from databases Mar 9, 2016 at 1:36
  • $_REQUEST["id"] that, is coming from somewhere. where? Mar 9, 2016 at 1:37
  • If you access to your page directly, obviously $_REQUEST is empty: you have to click to a link to send request.
    – fusion3k
    Mar 9, 2016 at 1:39

1 Answer 1

0

This script required id in the request

Method 01 : Get Method

Access script via url having id in the query parameter with value.

ie. http://localhost/youscript.php?id=7

Method 02: Post Method

Request page via form sending post data to your page.

<form method="post" action="your-page-url">
 <input name="id" type="text" placeholder="Enter your id" required>
 <input type="submit" value="Submit!">
</form>

make sure you have the field with name="id" attribute and it has value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.