Jump to content

Insert Query into Column


snizkorod

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/207458-insert-query-into-column/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.