Warning: unexpected character in input: " (ascii=29) state=0 in

18,014

Solution 1

The editor had added spaces that were not deletable. I had to delete several lines and rewrite them. So, this issue wasn't exactly with the code...just a text editor software problem.

The other error I had was a boolean error with my query. Turns out I was trying to query the database instead of the table.

Thanks for all the help with this!

Solution 2

Remove the single quotes from the column names in your query. This may not be the only error, if the PHP interpreter is still complaining about ASCII 29.

               $sql = "SELECT * from movies WHERE
                        (
                        'movie_title' LIKE '%keyword%'
                        OR
                        'movie_description' LIKE '%keyword%'
                        )";

               // Should be
               $sql = "SELECT * from movies WHERE
                        (
                        movie_title LIKE '%keyword%'
                        OR
                        movie_description LIKE '%keyword%'
                        )";
Share:
18,014
CherylAnnCE
Author by

CherylAnnCE

Learning PHP. Just getting started.

Updated on June 17, 2022

Comments

  • CherylAnnCE
    CherylAnnCE almost 2 years

    I've been reading about what others have done with this error and have made changes to my php.ini file, added code to override another php setting, and still end up with this same error. Here is my code:

     <html>
     <body>
     <table>
    
     <?php error_reporting (E_ALL ^ E_NOTICE); ?>
    
     <?php
    
         function getRecords($query) {
             $con = mysql_connect("localhost", "movie", "moviepw");
             if (!$con)
             {
                die('Could not connect: ' . mysql_error());
             }
    
             mysql_select_db("movies", $con);
    
             $result = mysql_query($query);
    
             // THE ERROR IS REPORTED ON THIS LINE
             return $result;
    
    }
    
              function buildQuery()  {
    
                        $keyword = $_GET['keyword'];
    
                        $sql = "SELECT * from movies WHERE
                                (
                                'movie_title' LIKE '%keyword%'
                                OR
                                'movie_description' LIKE '%keyword%'
                                )";
    
                        return $sql;  
    
            }
    
             $query = buildQuery();
    
             $records = getRecords($query);
    
             while($row = mysql_fetch_array($records)){ ?>
    
     <tbody>
              <table border='1'>
    
                <tr>
                       <td><?= $row['movie_title']; ?></td>
                       <td><?= $row['movie_rating']; ?></td>
                       <td> <img src="<?= $row['movie_image'];?>"> </td>
                       <td><?= $row['movie_description']; ?></td>
                       <td><a href="movie_index.php">Return to Search</a></td>
                </tr>
    
    <? }  ?>
    
    </tbody>
    
    </table>
    </body>
    </html>
    

    Any idea why I'm getting this error?

  • CherylAnnCE
    CherylAnnCE over 12 years
    Thank you so much for the idea. I gave this a go, too, but the issue was actually with some spaces that were oddly placed by my editor and wouldn't delete. Free software. ;-P
  • CherylAnnCE
    CherylAnnCE over 12 years
    Actually, I should have said that I fixed this. Thanks for pointing out this error, too.