my original code works ok which is:
//The basic SELECT statement
$select = 'SELECT id, name';
$from = ' FROM category';
$where = ' WHERE TRUE';
$placeholders = array();
if ($_GET['type']==1) //category is selected
{
$where .= " AND name LIKE :name";
$placeholders[':name'] = '%' . $_GET['text'] . '%';
try
{
$sql = $select . $from . $where;
$s = $pdo->prepare($sql);
$s->execute($placeholders);
}
catch (PDOException $e)
{
$error = 'product type error.';
include 'error.html.php';
exit();
}
However, I add a alternative type name called alter1, the code becomes:
//The basic SELECT statement
$select = 'SELECT id, name';
$from = ' FROM category';
$where = ' WHERE TRUE';
$placeholders = array();
if ($_GET['type']==1) //category is selected
{
$where .= " AND name LIKE :name OR name LIKE :alter1"; //new line
$placeholders[':name'] = '%' . $_GET['text'] . '%';
$placeholders[':alter1'] = '%' . $_GET['text'] . '%'; //new line
try
{
$sql = $select . $from . $where;
$s = $pdo->prepare($sql);
$s->execute($placeholders);
}
catch (PDOException $e)
{
$error = 'product type error.';
include 'error.html.php';
exit();
}
my problem is the alter1 seems not working correctly, I’m guessing I’m not doing right with the “placeholder part”