NerdConcepts Posted June 6, 2007 Share Posted June 6, 2007 Ok, some have read my other error topics. Here is something I have having fits with now. I import a .csv file into a temp database, then compare it to the permanent database. If the record is new it updates, if it is old it inserts it. No problem right? WRONG! There is a single field that has "FIRE'n UP Discount" in it. When the data moves from the temp database to the permanent one it throws the following code. MySQL Error: 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 'n UP Discount|DIU 18 MO','05/24/2007','2007-05' at line 1 Yes, that single quote is processed fine when importing the csv into the temp database. So what I am asking is how to I do this? I understand why it is throwing the code, just don't know how to fix it. I know there is a way to to completely copy information no matter if it is a single quote or not, I just cannot remember or figure out how to do it. If someone could help I would be really grateful Link to comment https://forums.phpfreaks.com/topic/54401-single-quote-issue/ Share on other sites More sharing options...
btherl Posted June 6, 2007 Share Posted June 6, 2007 Try using mysql_real_escape_string() on the data item before you put it in your mysql query. Single quotes are part of mysql's syntax. Link to comment https://forums.phpfreaks.com/topic/54401-single-quote-issue/#findComment-269002 Share on other sites More sharing options...
NerdConcepts Posted June 6, 2007 Author Share Posted June 6, 2007 Yeah, I know single quotes are a part of MySQL syntax, and I have been looking into the mysql_real_escape_string() function but I can't figure out to make it work with my application. Here is some code I use... $query = "SELECT * FROM csv_temp"; $result = mysql_query($query) or trigger_error("Query: $sql\n<br />MySQL Error: " . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $c01 = $row['ACKNOWLEDGED']; ... $qFind = "SELECT * FROM csv_data WHERE WORK_ORDER_NUMBER='$c14'"; $rFind = mysql_query($qFind) or trigger_error("Query: $qFind\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // Code to update is here } else { // Code to insert is here } } Am I supposed to do something like this with $c01 ? $c01 = mysql_real_escape_string($row['ACKNOWLEDGED'], $c01); ?? Not sure, I looked the command up but can't find any good examples that apply to what I am doing. Link to comment https://forums.phpfreaks.com/topic/54401-single-quote-issue/#findComment-269010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.