snizkorod Posted July 12, 2010 Share Posted July 12, 2010 Hello, I'm a new member so please forgive me if i am posting in the wrong board. I am interested in inserting a whole (legitimate) query into a TEXT column in the table that tracks admin actions on my website. This is the first time that i've been coding (only 2-3 months experience), so i'm not well-versed in the documentation. I've been searching around but so far the results don't look very helpful to me; hopefully some gurus on here will be helpful I have been trying to escape the sql statement before trying to insert it, but no luck there... As a start, here is the relevant code: $link = mysql_connect($_SESSION['server_name'], $_SESSION['server_user'], $_SESSION['server_pass']) or die(mysql_error()); if (get_magic_quotes_gpc()) { $action = stripslashes($action); $undo = stripslashes($undo); } //$undo and $action are set in a while loop before hand so i can't just put the statement here. $action = mysql_real_escape_string($action, $link); //text description of what is going on. $undo= mysql_real_escape_string($undo, $link); //the sql query i'm trying to convert to text. $admin = "INSERT INTO `db`.`table` (`adminID`, `date`, `action`, `undo`) VALUES ($ID, $time, $action, $undo)"; mysql_query($admin) or die("Report to admin that the admin news failed<br /><br />$admin<br /><br /> ". mysql_error()); /* OUTPUT: Report to admin that the admin news failed echoed query: insert into db.table (adminID, date, action, undo) values (2, 1278892801, snizkorod has updated player 9 by changing lname from test to testtest, numdays from 1 to 5, update molly.playaz set lname='test', numdays='1' where ID=9) 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 'undo) values (2, 1278892801, nooblord has updated player 9 by changing lname fro' at line 1 */ HERE IS THE MYSQL TABLE. #FieldTypeNullKeyDefaultExtra 1IDINTNOPRI[/td]auto_increment 2adminIDINTYESMUL 3dateINTNO 4actionTEXTNO 5undoTEXTNO[td] I would greatly appreciate your time and any helpful suggestions. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/207458-insert-query-into-column/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 12, 2010 Share Posted July 12, 2010 String data must be enclosed in single-quotes, making them strings instead of keywords. ..... VALUES ($ID, $time, '$action', '$undo')"; Quote Link to comment https://forums.phpfreaks.com/topic/207458-insert-query-into-column/#findComment-1084635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.