Warning: unexpected character in input: " (ascii=29) state=0 in
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?
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!
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%'
)";
链接地址: http://www.djcxy.com/p/69474.html