Jump to content

[SOLVED] Inserting into mysql


tomtom

Recommended Posts

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

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.

<?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']}';");
    }
?>

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.

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 :)

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.