My search box seen here works fine, but it has a bug. When a movie title has an ' apostrophe, the value wont change. Heres my code: while($searchArray = mysql_fetch_array($search)) { echo "<div onclick=\"javascript:document.getElementById('dvd_search').value='".$searchArray["" . $dvd_field[2][2] . ""]."'\"> <img src=\"images/list.gif\" border=\"0\"> ".$searchArray["" . $dvd_field[2][2] . ""]."</div>"; } PHP: Looking for some inspiration here ?
Escape single quotes. while($searchArray = mysql_fetch_array($search)) { echo "<div onclick=\"javascript:document.getElementById('dvd_search').value='".str_replace("'", "\'", $searchArray["" . $dvd_field[2][2] . ""])."'\"> <img src=\"images/list.gif\" border=\"0\"> ".$searchArray["" . $dvd_field[2][2] . ""]."</div>"; } PHP:
By the way, I didn't use addslashes() because it would also escape double quotes ("). Which could be part of a movie title.
That was the answer, thanks very much, however I ran into problems searching the db so I decided just to remove the apostrophe from all movie titles, thanks anyway.