The error is: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Case) VALUES ('744375')' at line 1"
<?php mysql_connect ('localhost', 'tet', 'pw'); mysql_select_db ('xcelfilter'); //1. define search term $searchterm = "Word"; //2. clear sorted table mysql_query('TRUNCATE TABLE sorted'); //3. for each, if search term is in the description column, put line into sorted table. $searchquery = "SELECT * FROM csv WHERE Description LIKE '%$searchterm%'"; $searchresult = mysql_query($searchquery) or die(mysql_error()); $row = mysql_fetch_row($searchresult); if (mysql_num_rows($searchresult) == 0) {echo "no rows found";} else { while ($row = mysql_fetch_array($searchresult)) { $case = $row['Case']; $case = mysql_real_escape_string($case); $case = stripslashes($case); $detail = $row['Detail']; $detail = mysql_real_escape_string($detail); $detail = stripslashes($detail); $summary = $row['Summary']; $summary = mysql_real_escape_string($summary); $summary = stripslashes($summary); $a_description = $row['Description']; $a_description = mysql_real_escape_string($a_description); $a_description = stripslashes($a_description); $name = $row['Name']; $name = mysql_real_escape_string($name); $name = stripslashes($name); // not working $query = "INSERT INTO sorted (Case) VALUES ('$case')"; // works //$query = "INSERT INTO sorted (Detail) // VALUES ('$detail')"; // works //$query = "INSERT INTO sorted (Summary) // VALUES ('$summary')"; // works //$query = "INSERT INTO sorted (Description) // VALUES ('$a_description')"; // works //$query = "INSERT INTO sorted (Name) // VALUES ('$name')"; // the whole thing .. not working because it has the "Case" in it. //$query = "INSERT INTO sorted ('Case', 'Detail', 'Summary', 'Description', 'Name') // VALUES ($case, $detail, $summary, $a_description, $name ) "; mysql_query($query) or die(mysql_error()); } // end while } // end else ?>