tags:

views:

58

answers:

1

Hi, every search query is saved in my database, but I want to Limit the Chracterlength for one single word: odisafuoiwerjsdkle --> length too much --> dont write in the database

my actually code is:

$search = $_GET['q']; 


    if (!($sql = mysql_query ('' . 'SELECT * FROM `history` WHERE `Query`=\'' . $search . '\'')))    {
      exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
      ;
    }

    while ($row = mysql_fetch_array ($sql))    {
      $ID = '' . $row['ID'];
    }

    if ($ID == '')
    {
      mysql_query ('' . 'INSERT INTO history (Query) values (\'' . $search . '\')');
    }

    if (!($sql = mysql_query ('SELECT * FROM `history` ORDER BY `ID` ASC LIMIT 1')))
    {
      exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
      ;
    }

    while ($row = mysql_fetch_array ($sql)) {
      $first_id = '' . $row['ID'];
    }

    if (!($sql = mysql_query ('SELECT * FROM `history`')))
    {
      exit ('<b>SQL ERROR:</b> 102, Cannot write history.');
      ;
    }
A: 

One option would be using a trigger in the table. But, if you are expecting a lot of traffic on your search engine it might not scale very well. So, using client side (PHP in your case) constraints might be a better choice.

Pablo Santa Cruz
thank you for the answer, have you any good method for me? or how to do that with php?
elmaso
`if(strlen($search) > 20){exit('Search string too long');}`
cmptrgeekken