MYSQL: Limit Word Length for MySql Insert

Posted by elmaso on Stack Overflow See other posts from Stack Overflow or by elmaso
Published on 2010-04-04T18:13:15Z Indexed on 2010/04/04 18:23 UTC
Read the original article Hit count: 243

Filed under:
|

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.');
      ;
    }

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql