473,325 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Problems writing to mySQL DB in PHP..

80
Hey everybody :D

I have a problem writing variables to my mySQL database using PHP. I am faerly new to php, and this problem seems to keep irritating me, so please help me hehe !! Thanks :D

When creating a var like:
Expand|Select|Wrap|Line Numbers
  1. $strSIP = $_SERVER['REMOTE_ADDR'];
And trying to put it into the mysql_query like:
Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT INTO `sys_session` (`ID`, `syslog_ip`)" .
  2. " VALUES ('', $strSIP)";
  3.  
  4. $result = mysql_query( $query );
I get the mysql_error:
You have an error in your SQL syntax near '.1.2)' at line 1
(I have trunk'd some of the code..)
What is wrong here? when i print or echo the $strSIP it gives the perfekt xxx.xxx.x.x IP.. The mySQL database is set up in syslog_ip as varchar(128)..

Thanks for any reply.
May 30 '09 #1
5 1902
hoopy
88
Hi you need to surround the variable in quotes if using characters like so:

Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT INTO `sys_session` (`ID`, `syslog_ip`)" ." VALUES ('','$strSIP')";
May 30 '09 #2
prabirchoudhury
162 100+
hey.. if you are using php >4.0 then you have to call IP address using getenv() function

Expand|Select|Wrap|Line Numbers
  1. $strSIP = getenv('REMOTE_ADDR');
  2.  
may be your sql insert ip field injecting empty..


look on PHP: getenv - Manual


:)
May 31 '09 #3
Markus
6,050 Expert 4TB
@prabirchoudhury
Using $_SERVER is perfectly fine, and, as his first post shows, the ip address is being populated.
May 31 '09 #4
Atli
5,058 Expert 4TB
@prabirchoudhury
That's just... not true.

Using $_SERVER['REMOTE_ADDR'] works fine in all versions later than 4.1.
Prior to that $HTTP_SERVER_VARS['REMOTE_ADDR'] was used
May 31 '09 #5
Pheddy
80
@hoopy
Using quotes around the variable, was the answer here :D Thank you!
Jun 1 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Andres Rosado-Sepulveda | last post by:
Hello, I'm having trouble compiling PHP 4.3.4 on Solaris 8. This is the error message it is showing: -- start -- Undefined first referenced symbol ...
2
by: Glenn | last post by:
Hi, I'm using cygwin and am trying to install DBI-mSQL and am getting errors on make .. any idea how to fix this (TIA): cpan> install DBD::mSQL Running install for module DBD::mSQL Running...
0
by: Davide Melloni | last post by:
Hi all, I'm not receiving your emails since this morning at 7:30AM. Are there some problems? Or maybe I have problems with my subscription but it's strange. Thanks in advance. Dave..... ...
0
by: Gabriel Harrison | last post by:
Hi, I know from the MySQL documentation that Windows in not case sensitive and Unix is but can I force Windows to honour upper and lower case in table names. When writing the mySQL on windows...
3
by: Kirk Soodhalter | last post by:
Hi, This started as a phpmyadmin problem, but has somehow morphed into a mysql problem. I don't know how to fix it. I am posting the conversation from a php newsgroup since it started there. ...
3
by: zeedan | last post by:
Hi, I appologise if I'm not posting this to the correct group, but I'm having problems starting MySQL server. I need it in order to post a websurvey for a research project I'm doing for a college...
6
by: M.A. Oude Kotte | last post by:
Hi All, I hope this is the correct mailing list for this question. But neither postgresql.org nor google could help me out on this subject. I did find one disturbing topic on the mailing list...
5
by: Frances | last post by:
a few days ago I installed XAMPP in my Windows 2000 machine, it completely messed my existing MySQL installation.. I've had it installed for over a year now (4.1) have never had any problems with...
3
by: Thorben Grosser | last post by:
Hello Newsgroup, I am doing some archive database and therefore got one table indexing every folder and one table storing which rack belongs to which department, eg: table folders :...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.