vendredi 20 juillet 2018

Warning: A non-numeric value encountered for text Values

i'm really new to this and was working on this homework where i was supposed to create a drop down list for the writers in my data base and as the user hovers over one of the authors the books that they wrote would show in an area on the same page , now i tried all i knew but i keep getting this error

"Warning: A non-numeric value encountered in C:\xampp\htdocs\demo\books.php on line 21"

even though the data in my database is all text, no need for any numeric values ..

i submitted the assignment just like that but i still want to know what i did wrong , i would really appreciate the help

            <?php

              $servername = "localhost";
              $username = "root";
              $password = "";
              $dbname = "books";

                 // variables used in script
              $Author =$_REQUEST["Author"];



                       // Create connection
                        $conn = new mysqli($servername, $username, $password, $dbname);

                       // Check connection
                       if (!$conn) {
                           die("Connection failed: " . mysqli_connect_error());
                       }

                       $sql = "SELECT BookName, BookID FROM `books`"+ 'WHERE AuthorName='+ '"'+'$Author'+'"';
            $sqlData=    mysqli_query($conn, $sql);


                if($sqlData)

                {
                while($row =mysqli_fetch_assoc($sqlData)){
                   echo" <table style='width:100%'>"+ "<tr> <th>BookName</th> <th>BookID</th> <th>AuthorName</th> </tr>"+"<tr> <td>"+ $row[BookName] +
                 "</td><td>"+$row[BookID] +"</td> </tr>";
                }
                echo "</table>" ;

                }





           ?>

this is the whole code where my drop down list is

    <!DOCTYPE html>


                    <html>
                       <head>
                          <meta charset = "utf-8">
                          <title>Books</title>
                          <style >
                             label  { width: 5em; float: left; }
                          </style>



                                <script  >

                                function ShowBook_Info(Author) {
                                    request=new XMLHttpRequest();
                                    request.onreadystatechange=function() {
                                        if (request.readyState==4 && request.status==200) {
                                            document.getElementById("books").innerHTML=request.responseText;
                                        }
                                    }

                                    request.open("GET","books.php?Author="+Author,true);
                                    request.send();
                                }

                            </script>


                       </head>

                           <?php

                          $servername = "localhost";
                          $username = "root";
                          $password = "";
                          $dbname = "books";



                             $sql="SELECT AuthorName FROM `books`";

                                   // Create connection
                                    $conn = new mysqli($servername, $username, $password, $dbname);

                                   // Check connection
                                   if (!$conn) {
                                       die("Connection failed: " . mysqli_connect_error());
                                   }



                               $sqlData=    mysqli_query($conn, $sql);

                               if($sqlData){



                                   echo "<select  onchange='ShowBook_Info(this.value)'>" ;
                                   while($row =mysqli_fetch_assoc($sqlData)){
                                       $Value=$row["AuthorName"];
                                       echo "<option value=";
                                       echo '$value'.'">';
                                       echo $row["AuthorName"];
                                       echo "</option>";


                                   }
                                   echo "</select>" ;


                               } else {
                                   echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                               }



                       ?>


                        <body  onload="ShowBook_Info('Harper Lee');" >



                              <div style="color:blue;" id='books'>
                     This is a test text

                     </div>

                          </form>
                       </body>
                    </html>




Aucun commentaire:

Enregistrer un commentaire