tomtom Posted July 28, 2008 Share Posted July 28, 2008 Now. I've been doing PHP for ages. But this is really bugging me. I'm working on an 'update' script. But that's all irrelavent. I've tried to do it neatly, and failed. You don't need to see the rest of the script - just this bit. I keep trying to run this script but it fails...it fails because of `content` - I know that. $install['code'] is a PHP script which is stored in another mysql - it's not $install that is broken as all the other $install's work. If you follow. So I'm wondering WHY this doesn't work. Is there a special way of doing it. When $code = "tom"; it works. It's just because $install['code'] is a PHP script I reckon. Much appreciated. Sorry if badly explained - just ask me if you need any extra info. Thanks in advance. <?php $code=$install['code']; $copy_code = mysql_query("UPDATE `modules` SET `updated` = '" . time() . "', `version` = '" . $install['version'] . "', `lang` = '" . $install['lang'] . "', `product_id` = '" . $install['product_id'] . "', `content` = '$code' WHERE `id` = '" . $folder['5'] . "'"); ?> Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/ Share on other sites More sharing options...
jonsjava Posted July 28, 2008 Share Posted July 28, 2008 ok, I cleared up the code some (just made it easier to read. it should work as you had it) <?php $code=$install['code']; $time = time(); $copy_code = mysql_query("UPDATE `modules` SET `updated` = '{$time}', `version` = '{$install['version']}', `lang` = '{$install['lang']}', `product_id` = '{$install['product_id']}', `content` = '{$code}' WHERE `id` = '{$folder['5']}';"); ?> Now, the question. Where do you run the query? I see you define a variable to be the query, but I don't see you calling the query. It won't run until you do. Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/#findComment-601595 Share on other sites More sharing options...
tomtom Posted July 28, 2008 Author Share Posted July 28, 2008 <?php $get_install_id = mysql_query("SELECT * from `update` WHERE `id` = '" . $folder['4'] . "'"); while($install = mysql_fetch_array($get_install_id)) { $code=$install['code']; $time = time(); $copy_code = mysql_query("UPDATE `modules` SET `updated` = '{$time}', `version` = '{$install['version']}', `lang` = '{$install['lang']}', `product_id` = '{$install['product_id']}', `content` = '{$code}' WHERE `id` = '{$folder['5']}';"); } ?> Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/#findComment-601598 Share on other sites More sharing options...
jonsjava Posted July 28, 2008 Share Posted July 28, 2008 $copy_code = mysql_query("UPDATE `modules` SET `updated` = '{$time}', `version` = '{$install['version']}', `lang` = '{$install['lang']}', `product_id` = '{$install['product_id']}', `content` = '{$code}' WHERE `id` = '{$folder['5']}';"); Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/#findComment-601599 Share on other sites More sharing options...
jonsjava Posted July 28, 2008 Share Posted July 28, 2008 never mind. I focused on the wrong line. Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/#findComment-601601 Share on other sites More sharing options...
jonsjava Posted July 28, 2008 Share Posted July 28, 2008 as for your issue with <?php $code=$install['code']; There is no possible way for us to give you a viable answer with just that as our only hint to the problem Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/#findComment-601604 Share on other sites More sharing options...
tomtom Posted July 28, 2008 Author Share Posted July 28, 2008 ah i understand but. I think it's just because I'm getting a PHP script from a database and putting it into another one. If I just echo $install['code'] - it works. It's just inserting it into another database. It's hard to explain. It makes the error: Invalid query: 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 'uniquename'); return true;\">None"; function MakeChilds($nav,$info) { $curr' at line 1 I think it is trying to run the code as opposed to just inserting it. Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/#findComment-601605 Share on other sites More sharing options...
tomtom Posted July 28, 2008 Author Share Posted July 28, 2008 aha! fixed <?php $copy_code = mysql_query("UPDATE `modules` SET `updated` = '{$time}', `version` = '{$install['version']}', `lang` = '{$install['lang']}', `product_id` = '{$install['product_id']}', `content` = '" . addslashes($install['code']) . "' WHERE `id` = '{$folder['5']}';"); ?> I needed addslashes(); Thanks for your help Link to comment https://forums.phpfreaks.com/topic/116981-solved-inserting-into-mysql/#findComment-601613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.