deymer Posted August 8, 2010 Share Posted August 8, 2010 i have a with my script I made a basic messaging service for my website. I have a form with a textarea as an input variable. It inserts the textarea value to a database using a php script upon form submission. The SQL field is set as longtext so the user can insert a large text string. There's a few things i need to do to perfect it. I need to make it so the user can only insert text characters, so not to allow script manipulation; and I need to figure out why it's deleting my intro message when changing the `read` field from `unread` to `read`. The `messages` SQL table is separated into 6 fields: to, from, message, read, subject, and number. when the user reads a message, i have a php script that reads as follows: <?php include("include/session.php"); function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } $pagename = curPageName(); $replaced2 = eregi_replace("message", "", $pagename); $number = eregi_replace(".php", "", $replaced2); mysql_select_db("******_starcraft") or die(mysql_error()) ; $query = " SELECT * FROM `messages` WHERE number='$number' "; $result = mysql_query($query); $info = mysql_fetch_array ( $result ); $to = $info['to']; $from = $info['from']; $subject = $info['subject']; $message = $info['message']; $read = $info['read']; mysql_query("DELETE FROM `messages` WHERE `number`='$number'") ; mysql_query("INSERT INTO `messages` VALUES ('$to', '$from', '$message', 'read', '$subject', '$number')") ; ?> Now, after trouble shooting, i found that the problem is occuring when it tries to insert the $message string into the third field of the `messages` table. I find this strange because when you send the message to this user using the "compose message" script, the input variable is inserted into the database table without a stitch. Is there something i'm missing? i feel like it's on the tip of my tounge... thanks in advance, -dan Quote Link to comment https://forums.phpfreaks.com/topic/210098-problem-inserting-longtext-field-mysql-php/ Share on other sites More sharing options...
RussellReal Posted August 8, 2010 Share Posted August 8, 2010 I'm not exactly sure you're updating by deleting a row then re-adding the row.. why not just UPDATE? Quote Link to comment https://forums.phpfreaks.com/topic/210098-problem-inserting-longtext-field-mysql-php/#findComment-1096471 Share on other sites More sharing options...
deymer Posted August 9, 2010 Author Share Posted August 9, 2010 I never learned how to update, I've always used the delete and add method. It's wired in the past. How do you use update, example please Quote Link to comment https://forums.phpfreaks.com/topic/210098-problem-inserting-longtext-field-mysql-php/#findComment-1096829 Share on other sites More sharing options...
jcbones Posted August 9, 2010 Share Posted August 9, 2010 http://dev.mysql.com/doc/refman/5.0/en/update.html UPDATE table SET col = 'value' WHERE col = 'value'; Quote Link to comment https://forums.phpfreaks.com/topic/210098-problem-inserting-longtext-field-mysql-php/#findComment-1096832 Share on other sites More sharing options...
RussellReal Posted August 9, 2010 Share Posted August 9, 2010 http://dev.mysql.com/doc/refman/5.0/en/update.html UPDATE table SET col = 'value' WHERE col = 'value'; haha you following me JCB? <3 Quote Link to comment https://forums.phpfreaks.com/topic/210098-problem-inserting-longtext-field-mysql-php/#findComment-1096929 Share on other sites More sharing options...
jcbones Posted August 9, 2010 Share Posted August 9, 2010 I'm the Stalker Quote Link to comment https://forums.phpfreaks.com/topic/210098-problem-inserting-longtext-field-mysql-php/#findComment-1097187 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.