Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-14-2003, 12:36 PM   #1 (permalink)
jimmyoctane
Registered User
 
jimmyoctane's Avatar
 
Join Date: Sep 2003
Location: California
Posts: 26
jimmyoctane is on a distinguished road
Send a message via AIM to jimmyoctane
MYSQL - insert

I am modifing a script I borrowed and am trying to get info
from the visitor to my site.

I have it so I can display the data to the screen but would like to write to mysql database :

================================================== ================
$browser = $client->property('browser');
$longname = $client->property('long_name');
$version = $client->property('version');
$javascript = $client->property('javascript');
$platform = $client->property('platform');
$os = $client->property('os');
$ip = $client->property('ip');
$language = $client->property('language');


//$mysqlinsert = mysql_query("INSERT INTO userlog VALUES("$browser", "$longname", "$version", "$javascript", "$platform", "$os", "$ip", "language" ");

print $browser;
print $longname;
print $version;
print $javascript;
print $platform;
print $os;
print $ip;
print $language;

?>
================================================== ================
not sure how to do the INSERT part only been at this a couple of days
jimmyoctane is offline   Reply With Quote
Old 09-14-2003, 06:14 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
I'm not really familiar with PHP, but was wondering if PHP was smart enough to tell that an identifier beginning with a '$' inside a quote was a variable rather than a literal?

At any rate, you have missmatched parens, and I'm willing to bet that your quotes are missmatched as well. And it looks like you forgot a '$' in front of 'language'.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 09-14-2003, 07:01 PM   #3 (permalink)
jimmyoctane
Registered User
 
jimmyoctane's Avatar
 
Join Date: Sep 2003
Location: California
Posts: 26
jimmyoctane is on a distinguished road
Send a message via AIM to jimmyoctane
mysql insert

The "$" is missing from variable and you are right that the data in double quotes is seen as a char value instead of actual field value....but I think that doesnt matter at this point. The data should still be written to the database.
The record would look like this:

database: userlog
field: Browser = "$browser"
field: longname = "$longname"
field: version = "$version"
field: javascript = "$javascript"
field: platform = "$platform"
field: os = "$os"
field: ip = "$ip"
field: language = "language"







Just unsure of syntax.

I just pulled this section of code out of a much larger program.



Thanks for the reply
database: userlog
jimmyoctane is offline   Reply With Quote
Old 09-14-2003, 09:20 PM   #4 (permalink)
jimmyoctane
Registered User
 
jimmyoctane's Avatar
 
Join Date: Sep 2003
Location: California
Posts: 26
jimmyoctane is on a distinguished road
Send a message via AIM to jimmyoctane
insert-mysql

Okay I got it

here goes

$query = "INSERT INTO userlog ( browser , long_name , version , javascript ,
platform , os , ip , language ) VALUES ('$browser', '$longname', '$version',
'$javascript', '$platform', '$os', '$ip', '$language' )";

$result = mysql_query($query);


thanks
jimmyoctane is offline   Reply With Quote
Old 09-15-2003, 10:25 AM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
I think you still have the quoting problem. Here's how I would do it (again, I'm not familiar with PHP).

$query = "INSERT INTO userlog (browser, long_name, version, javascript, platform, os, ip, language) VALUES ('" + $browser + "','" + $longname + "','" + $version + "','" + $javascript + "','" + $platform + "','" + $os + "','" + $ip + "','" + $language + "')";

You need to escape out of the quote for each variable.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 09-15-2003, 10:48 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
while it may be good practice, php doesn't require you to isolate the variables like that .. ( except in certain instances like when your using objects )

also, when you are isolating variables, php uses '.' not '+'

so your query string would look like this:
PHP Code:
<?
$query 
"INSERT INTO userlog (browser, long_name, version, javascript, platform, os, ip, language) 
     VALUES ('" 
$browser "','" $longname "','" $version "','" $javascript "','" $platform "','" $os "','" $ip "','" $language "')";
?>
but jimmy's way will work fine too =)
__________________
Mike
sde is offline   Reply With Quote
Old 09-15-2003, 12:43 PM   #7 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
Grrr, non-#!@$-C syntax.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 09-15-2003, 01:15 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
i know .. i go between php and c# a lot and will mix up my . and + once in a while.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML form preview then INSERT using PHP & MySQL SteveSoler PHP 13 08-27-2008 10:47 PM
and on to mysql .. sde Linux / BSD / OS X 2 01-18-2003 07:39 PM
MySQL problems sde Linux / BSD / OS X 5 12-07-2002 10:04 PM


All times are GMT -8. The time now is 05:06 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting