开发者

Update Query clearing results through PHP

开发者 https://www.devze.com 2023-04-05 14:34 出处:网络
I\'m developing under my development machine in PHP and connecting to the database remotly. I uploaded the files to the server and online the query works as expected but in localhost it doesn\'t. All

I'm developing under my development machine in PHP and connecting to the database remotly. I uploaded the files to the server and online the query works as expected but in localhost it doesn't. All other queries work!

I have a block of code to insert a new record at the database or update if it already exists.

The code is:

            $name = mysql_real_escape_string($_REQUEST['name']);
            $title = mysql_real_escape_string($_REQUEST['title']);
            $content = $_REQUEST['content'];
    $lang_drop = mysql_real_escape_string($_REQUEST['lang']);
            if($uid == 0)
            {
                $maxSort = tools::getInfo($table, Array(开发者_运维技巧), Array('MAX(sort_order) as sort_order'));
                $maxSort = $maxSort[0]['sort_order']+1;
                    $sql="insert into quemsomos (title,name,lang,sort_order)
                            values(
                                '$title',
                                '$name',
                                '$lang_drop',
                                $maxSort
                            )";
                        echo $sql;
                    mysql_query($sql);
                    $uid = mysql_insert_id();
            }
            else{
$maxSort = $data['sort_order'];
                    $sql="update `quemsomos` set `title`='blabkalm', `name`='{$name}', `lang`='{$lang_drop}', `sort_order`=$maxSort where `uid`={$uid}";
                    mysql_query($sql);
                    echo $sql;
                }

Pretty simple... If I insert a new record it works fine and $sql value printed is:

insert into quemsomos (title,name,lang,sort_order) values('title412', 'name421', 'pt', 3 )

The problem is that when I update the query executes but only the hardcoded values are stored in database. I mean, after the bellow update all values in the DB are empty except for sort_order which is saved and title (because it's hardcoded... if i place the right variable the field gets blank also)

echo $sql for the update statement returns the following:

update `quemsomos` set `title`='blabkalm', `name`='name421', `lang`='pt', `sort_order`=3 where `uid`=2

As you can see all values are there and if I run this query manually all works out fine...

Does this make sense to anyone?


I think this part

`uid`={$uid}";

is not okay. You can be very sure like this:

$sq='\''; 
$sql="update `quemsomos` set `title`='blabkalm', `name`=".$sq.$name.$sq.", `lang`=".$sq.
$lang_drop.$sq.", `sort_order`=".$sq.$maxSort.$sq." where `uid`=".$sq.$uid.$sq."   ";

This must work.

An other thing.. mysql error can help a lot in debugging cause output the error, don't forget to use it:

mysql_query($sql) or die(mysql_error());   
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号