TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Need Help Mysql Query (http://www.talkphp.com/general/1330-need-help-mysql-query.html)

biggerboy 10-24-2007 01:04 AM

Need Help Mysql Query
 
Here is what I have

PHP Code:

$query sprintf"insert into images set realname='%s', 
user='%s', size='%s', used='%s',
type='%s', desc='%s', ip='%s', 
private='1', report='0'"
$filename_orig$username$filesize$date$filetype$desc$_SERVER['REMOTE_ADDR']); 

I am getting as an error T_LNUMBER where the private and report entries are.

Thanks!

Gurnk 10-24-2007 01:21 AM

This is all I use to insert something into a table. It seems to work for me. I don't know if you can use the sprintf function with this method, as I'm not to familiar with sprintf.
PHP Code:

$query "INSERT INTO images (field, field, field) VALUES ('$variable', '$variable', '$variable')";
$result mysql_query($query); 

Of course you can do that in one variable, but I like having them separate.

Wildhoney 10-24-2007 01:24 AM

I've reshuffled your query and everything appears to be working fine. I don't know where the error was coming from. Incidentally, if you're new to PHP then you may wish to read this article. It will help you get a better understanding of what types of variables you are dealing with.

PHP Code:

$query sprintf("    INSERT INTO
                        images
                    SET
                        realname = '%s',
                        user =  '%s',
                        size = %d,
                        used = '%s',
                        type = '%s',
                        desc = '%s',
                        ip = '%s', 
                        private = %d,
                        report = %d"

                        
$filename_orig,
                        
$username,
                        
$filesize,
                        
$date,
                        
$filetype,
                        
$desc,
                        
$_SERVER['REMOTE_ADDR'],
                        
1,
                        
0); 


Wildhoney 10-24-2007 01:25 AM

Gurnk, you may wish to read this article on sprintf whilst I'm here referring people elsewhere :) !


All times are GMT. The time now is 11:53 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0