lordvader
12-28-2007, 06:47 PM
Hi,
I've written a basic PHP script that recieves a character from an AJAX function and then searches through a database to look for words begining with that character. Any words that are found are passed back to the AJAX function.
The code all works and the page does what I want it to do, but I've been told that I need to add some slashes or do some escaping (whom I cannot ask for further assistance), and I'm not sure where this would need to be done or why.
Here's the PHP:
<?php
$host = "localhost";
$user = "root";
$password = "mypassword";
$database = "mydata";
$server = mysql_connect($host, $user, $password);
$connection = mysql_select_db($database, $server);
$param = $_GET['query'];
$query = mysql_query("SELECT * FROM products WHERE product LIKE '$param%'");
for ($x = 0; $x < mysql_num_rows($query); $x++) {
$row = mysql_fetch_assoc($query);
$output = $row['product']."\n";
echo $output;
}
mysql_close($server);
?>
I don't do anything more than dabble with PHP unfortunately, so any help at all would be hugely appreciated
I've written a basic PHP script that recieves a character from an AJAX function and then searches through a database to look for words begining with that character. Any words that are found are passed back to the AJAX function.
The code all works and the page does what I want it to do, but I've been told that I need to add some slashes or do some escaping (whom I cannot ask for further assistance), and I'm not sure where this would need to be done or why.
Here's the PHP:
<?php
$host = "localhost";
$user = "root";
$password = "mypassword";
$database = "mydata";
$server = mysql_connect($host, $user, $password);
$connection = mysql_select_db($database, $server);
$param = $_GET['query'];
$query = mysql_query("SELECT * FROM products WHERE product LIKE '$param%'");
for ($x = 0; $x < mysql_num_rows($query); $x++) {
$row = mysql_fetch_assoc($query);
$output = $row['product']."\n";
echo $output;
}
mysql_close($server);
?>
I don't do anything more than dabble with PHP unfortunately, so any help at all would be hugely appreciated